Dear All,
I am trying to set a psi4.Vector using a np array as input. The syntax I am trying to use is the following consider I have a np vector x:
n=x.size
vec=psi4.Vector(n)
vec.set(x)
but this seems to throw out an error. I would appreciate any suggestion you might have.
Thank you in advance.
Best,
Shachar
Hello Scachar,
It looks like we did not export the non-irreped form of this to python, you can use vec.set(0, x)
for your operation currently.
As a note probably the best way to go from a NumPy array to a Psi4 vector is the following:
a = np.random.rand(5)
b = psi4.Vector(5)
b_view = np.asarray(b) # Take a view of b
b_view[:] = a # Set b to a
b.print_out() # Check the array
The np.asarray
syntax will not copy the data, but create a NumPy array that is a view of the Psi4 Matrix. Since all of these arrays are just double*
's under the hood we can pass the memory position around arbitrarily.