def qzeros(size, **kwargs): ''' Produces a qmatrix of zeroes, similar to numpy.zeros. Accepts dtype argument. >>> qzeros((2,3)) 1 1 1 1 0.0 0.0 0.0 1 0.0 0.0 0.0 >>> qzeros(2) 1 1 1 0.0 0.0 >>> qzeros((2,3), dtype=int16) 1 1 1 1 0 0 0 1 0 0 0 ''' if (not isinstance(size, tuple)): size = (1, size) if len(size) > 2: raise QuantMatrixError, "Enter a tuple of size <= 2." if kwargs.has_key('dtype'): return QuantMatrix(numpy.zeros(size, dtype=kwargs['dtype']), [ qhomogeneous(size[0], dimensionless().dim), qhomogeneous(size[1], dimensionless().dim) ], True) return QuantMatrix(numpy.zeros(size), [ qhomogeneous(size[0], dimensionless().dim), qhomogeneous(size[1], dimensionless().dim) ], True)
def qzeros(size, **kwargs): ''' Produces a qmatrix of zeroes, similar to numpy.zeros. Accepts dtype argument. >>> qzeros((2,3)) 1 1 1 1 0.0 0.0 0.0 1 0.0 0.0 0.0 >>> qzeros(2) 1 1 1 0.0 0.0 >>> qzeros((2,3), dtype=int16) 1 1 1 1 0 0 0 1 0 0 0 ''' if (not isinstance(size,tuple)): size = (1,size) if len(size)>2: raise QuantMatrixError, "Enter a tuple of size <= 2." if kwargs.has_key('dtype'): return QuantMatrix(numpy.zeros(size, dtype=kwargs['dtype']), [qhomogeneous(size[0], dimensionless().dim), qhomogeneous(size[1],dimensionless().dim)], True) return QuantMatrix(numpy.zeros(size), [qhomogeneous(size[0], dimensionless().dim), qhomogeneous(size[1],dimensionless().dim)], True)
def qmat(array): ''' Casts array into a QuantMatrix. >>> a = array([[1,2],[3,4]]) >>> qmat(a) 1 1 1 1 2 1 3 4 ''' if (not isinstance(array, numpy.ndarray)) or (not len(array.shape) == 2): raise QuantMatrixError, "qmat takes a two dimensional ndarray as its argument." return QuantMatrix(array, [ qhomogeneous(array.shape[0], dimensionless().dim), qhomogeneous(array.shape[1], dimensionless().dim) ], True)
def qmat(array): ''' Casts array into a QuantMatrix. >>> a = array([[1,2],[3,4]]) >>> qmat(a) 1 1 1 1 2 1 3 4 ''' if (not isinstance(array, numpy.ndarray)) or (not len(array.shape)==2): raise QuantMatrixError, "qmat takes a two dimensional ndarray as its argument." return QuantMatrix(array, [qhomogeneous(array.shape[0], dimensionless().dim), qhomogeneous(array.shape[1], dimensionless().dim)], True)
def qidentity(size, **kwargs): ''' Creates the identitiy matrix of size size. >>> qidentity(3) 1 1 1 1 1.0 0.0 0.0 1 0.0 1.0 0.0 1 0.0 0.0 1.0 ''' if kwargs.has_key('dtype'): return QuantMatrix(numpy.identity(size, dtype=kwargs['dtype']), [qhomogeneous(size, dimensionless().dim), qhomogeneous(size, dimensionless().dim)], True) return QuantMatrix(numpy.identity(size), [qhomogeneous(size, dimensionless().dim), qhomogeneous(size, dimensionless().dim)], True)
def qidentity(size, **kwargs): ''' Creates the identitiy matrix of size size. >>> qidentity(3) 1 1 1 1 1.0 0.0 0.0 1 0.0 1.0 0.0 1 0.0 0.0 1.0 ''' if kwargs.has_key('dtype'): return QuantMatrix(numpy.identity(size, dtype=kwargs['dtype']), [ qhomogeneous(size, dimensionless().dim), qhomogeneous(size, dimensionless().dim) ], True) return QuantMatrix(numpy.identity(size), [ qhomogeneous(size, dimensionless().dim), qhomogeneous(size, dimensionless().dim) ], True)
def qcolumn_vector(raw_numbers, quantities): ''' A quick constructor for a column vector. >>> qcolumn_vector((1,2,3),(meter,second,mole)) 1 m 1.0 s 2.0 mol 3.0 ''' matrix = [] for element in raw_numbers: matrix.append([element]) return QuantMatrix(numpy.array(matrix), [list(quantities),[dimensionless()]])
def qcolumn_vector(raw_numbers, quantities): ''' A quick constructor for a column vector. >>> qcolumn_vector((1,2,3),(meter,second,mole)) 1 m 1.0 s 2.0 mol 3.0 ''' matrix = [] for element in raw_numbers: matrix.append([element]) return QuantMatrix(numpy.array(matrix), [list(quantities), [dimensionless()]])