docstr: Create square diagonal matrix using given list.
  
  Example:
  >>> from mpmath import diag, mp
  >>> mp.pretty = False
  >>> diag([1, 2, 3])
  matrix(
  [['1.0', '0.0', '0.0'],
   ['0.0', '2.0', '0.0'],
   ['0.0', '0.0', '3.0']])
docstr_tok: ["Create","square","diagonal","matrix","using","given","list",".","Example",":",">",">",">","from","mpmath","import","diag",",","mp",">",">",">","mp.pretty","=","False",">",">",">","diag","(","[","1",",","2",",","3","]",")","matrix","(","[","[","'","1.0","'",",","'","0.0","'",",","'","0.0","'","]",",","[","'","0.0","'",",","'","2.0","'",",","'","0.0","'","]",",","[","'","0.0","'",",","'","0.0","'",",","'","3.0","'","]","]",")"]
code: def diag(ctx, diagonal, **kwargs):
      """
      Create square diagonal matrix using given list.
  
      Example:
      >>> from mpmath import diag, mp
      >>> mp.pretty = False
      >>> diag([1, 2, 3])
      matrix(
      [['1.0', '0.0', '0.0'],
       ['0.0', '2.0', '0.0'],
       ['0.0', '0.0', '3.0']])
      """
      A = ctx.matrix(len(diagonal), **kwargs)
      for i in xrange(len(diagonal)):
          A[i, i] = diagonal[i]
      return A
  
imports: from ..libmp.backend import xrange
  import warnings
label_desc: Use image node_id 3 for calling the MatrixMethods obj's underlying member method code with example usage: obj.diag(ctx, diagonal) and returns: A