array_to_matrix¶
- psi4.driver.p4util.array_to_matrix(self, arr, name='New Matrix', dim1=None, dim2=None)[source]¶
Converts a NumPy array or list of NumPy arrays into a PSI4
Matrix
orVector
(irrepped if list).- Parameters:
arr (
Union
[ndarray
,List
[ndarray
]]) – NumPy array or list of arrays to use as the data for a newMatrix
orVector
.dim1 (
Union
[List
,Tuple
,Dimension
,None
]) – If a single dense NumPy array is given, a dimension can be supplied to apply irreps to this array. Note that this discards all extra information given in the matrix besides the diagonal blocks determined by the passed dimension.dim2 (
Optional
[Dimension
]) – Same as dim1 only if using aDimension
object.
- Returns:
Returns the given (self) Psi4 object.
- Return type:
Notes
This is a generalized function to convert a NumPy array to a Psi4 object
Examples
>>> data = np.random.rand(20,1) >>> vector = psi4.core.Matrix.from_array(data)
>>> irrep_data = [np.random.rand(2, 2), np.empty(shape=(0,3)), np.random.rand(4, 4)] >>> matrix = psi4.core.Matrix.from_array(irrep_data) >>> print(matrix.rowdim().to_tuple()) (2, 0, 4)