Vector

class psi4.core.Vector

Bases: ProtoVector

Class for creating and manipulating vectors

Attributes Summary

name

The name of the Vector.

np

View with single irrep.

nph

View with irreps.

shape

Shape of the Psi4 data object.

Methods Summary

add(*args, **kwargs)

Overloaded function.

array_interface(self)

axpy(self, a, other)

Adds to this vector another vector scaled by a

clone(self)

Clone the vector

copy(self, arg0)

Copy another vector into this.

dim(self[, h])

Returns the dimensions of the vector per irrep h

dimpi(self)

Returns the Dimension object

from_array([name, dim1, dim2])

Converts a NumPy array or list of NumPy arrays into a PSI4 Matrix or Vector (irrepped if list).

from_list(x)

from_serial()

Converts serialized data to the correct Psi4 data type

get(*args, **kwargs)

Overloaded function.

get_block(self, slice)

Get a vector block

init(self, arg0)

Reallocate the data of the Vector.

load(self, psio, file)

Load the vector from disk

nirrep(self)

Returns the number of irreps

np_read([prefix])

Reads the data from a NumPy compressed or uncompressed file using numpy.load().

np_write([filename, prefix])

Writes the irrepped matrix to a NumPy uncompressed file using numpy.savez().

print_out(self)

Prints the vector to the output file

save(self, psio, file)

Save the vector to disk

scale(self, sc)

Scales the elements of a vector by sc

set(*args, **kwargs)

Overloaded function.

set_block(self, slice, block)

Set a vector block

to_array([copy, dense])

Converts a PSI4 Matrix or Vector to a NumPy array.

to_serial()

Converts an object with a .nph accessor to a serialized dictionary

vector_dot(self, other)

Take the dot product of two vectors

zero(self)

Zeros the vector

Attributes Documentation

name

The name of the Vector. Used in printing.

np

View with single irrep.

nph

View with irreps.

shape

Shape of the Psi4 data object.

Methods Documentation

add(*args, **kwargs)

Overloaded function.

  1. add(self: psi4.core.Vector, m: int, val: float) -> None

Add to a single element value located at m

  1. add(self: psi4.core.Vector, h: int, m: int, val: float) -> None

Add to a single element value located at m in irrep h

array_interface(self: psi4.core.Vector) list
axpy(self: psi4.core.Vector, a: float, other: psi4.core.Vector) None

Adds to this vector another vector scaled by a

clone(self: psi4.core.Vector) psi4.core.Vector

Clone the vector

copy(self: psi4.core.Vector, arg0: psi4.core.ProtoVector) None

Copy another vector into this.

dim(self: psi4.core.Vector, h: int = 0) int

Returns the dimensions of the vector per irrep h

dimpi(self: psi4.core.Vector) psi4.core.Dimension

Returns the Dimension object

classmethod from_array(name='New Matrix', dim1=None, dim2=None)

Converts a NumPy array or list of NumPy arrays into a PSI4 Matrix or Vector (irrepped if list).

Parameters:
  • self (Union[Matrix, Vector]) – Matrix or Vector class.

  • arr (Union[ndarray, List[ndarray]]) – NumPy array or list of arrays to use as the data for a new Matrix or Vector.

  • name (str) – Name to give the new Matrix.

  • 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 a Dimension object.

Returns:

Returns the given (self) Psi4 object.

Return type:

Matrix or Vector

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)
classmethod from_list(x)
classmethod from_serial()

Converts serialized data to the correct Psi4 data type

Parameters:
  • self – Pointer to which class to be constructed.

  • json_data (Dict[str, Any]) – Serialization of class. See to_serial() for data layout.

Return type:

Union[Matrix, Vector]

get(*args, **kwargs)

Overloaded function.

  1. get(self: psi4.core.Vector, m: int) -> float

Returns a single element value located at m

  1. get(self: psi4.core.Vector, h: int, m: int) -> float

Returns a single element value located at m in irrep h

get_block(self: psi4.core.Vector, slice: psi4.core.Slice) psi4.core.Vector

Get a vector block

init(self: psi4.core.Vector, arg0: psi4.core.Dimension) None

Reallocate the data of the Vector. Consider making a new object.

load(self: psi4.core.Vector, psio: psi4.core.IO, file: int) None

Load the vector from disk

nirrep(self: psi4.core.Vector) int

Returns the number of irreps

classmethod np_read(prefix='')

Reads the data from a NumPy compressed or uncompressed file using numpy.load().

Parameters:
  • self (Union[Matrix, Vector]) – Pointer to which class to be constructed.

  • filename (str) – File name to read.

  • prefix (str) – Name under which array was saved for NumPy.

Return type:

Union[Matrix, Vector]

np_write(filename=None, prefix='')

Writes the irrepped matrix to a NumPy uncompressed file using numpy.savez().

Can return the packed data for saving many matrices into the same file.

Parameters:
  • self (Union[Matrix, Vector]) – Instance to be serialized.

  • filename (Optional[str]) – File name where the data will be saved.

  • prefix (str) – Name of instance prepared for NumPy.

Returns:

When filename given, it and dict serialization passed to numpy.savez(), so .npz file saved and None returned. When filename None, dict serialization returned.

Return type:

None or Dict[str, Any]

print_out(self: psi4.core.Vector) None

Prints the vector to the output file

save(self: psi4.core.Vector, psio: psi4.core.IO, file: int) None

Save the vector to disk

scale(self: psi4.core.Vector, sc: float) None

Scales the elements of a vector by sc

set(*args, **kwargs)

Overloaded function.

  1. set(self: psi4.core.Vector, m: int, val: float) -> None

Sets a single element value located at m

  1. set(self: psi4.core.Vector, h: int, m: int, val: float) -> None

Sets a single element value located at m in irrep h

set_block(self: psi4.core.Vector, slice: psi4.core.Slice, block: psi4.core.ProtoVector) None

Set a vector block

to_array(copy=True, dense=False)

Converts a PSI4 Matrix or Vector to a NumPy array. Either copies the data or simply constructs a view.

Parameters:
  • matrix (Union[Matrix, Vector]) – Pointers to which Psi4 core class should be used in the construction.

  • copy (bool) – Copy the data if True, return a view otherwise

  • dense (bool) – Converts irrepped Psi4 objects to diagonally blocked dense arrays if True. Returns a list of arrays otherwise.

Returns:

Returns a single or list of NumPy arrays depending on options.

Return type:

ndarray or List[ndarray]

Notes

This is a generalized function to convert a Psi4 object to a NumPy array

Examples

>>> data = psi4.core.Matrix(3, 3)
>>> data.to_array()
[[ 0.  0.  0.]
 [ 0.  0.  0.]
 [ 0.  0.  0.]]
to_serial()

Converts an object with a .nph accessor to a serialized dictionary

Parameters:

self (Union[Matrix, Vector]) – Matrix or Vector instance.

Returns:

Serialized dictionary with keys:

  • shape

  • data : List[str]

  • type : {‘matrix’, ‘vector’}

Return type:

Dict[str, Any]

vector_dot(self: psi4.core.Vector, other: psi4.core.Vector) float

Take the dot product of two vectors

zero(self: psi4.core.Vector) None

Zeros the vector