#NEWLINE# def setter_scalar( value , dim_x ) : #NEWLINE# #INDENT# " Returns a copy of 'value' as an numpy.array with dtype=float. Throws\n    exception if the array is not dimensioned correctly. Value may be any\n    type which converts to numpy.array (list, np.array, np.matrix, etc),\n    or a scalar, in which case we create a diagonal matrix with each\n    diagonal element == value.\n\n    dim_x is used iff value is scalar, otherwise it is determined from the\n    shape of value\n    " #NEWLINE# if isscalar ( value ) : #NEWLINE# #INDENT# v = ( eye ( dim_x ) * value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# v = array ( value , dtype = float ) #NEWLINE# dim_x = value . shape [ 0 ] #NEWLINE# #UNINDENT# if ( v . shape != ( dim_x , dim_x ) ) : #NEWLINE# #INDENT# raise Exception ( 'must have shape ({},{})' . format ( dim_x , dim_x ) ) #NEWLINE# #UNINDENT# return v