Page 1 of 1

Numpy array to hoc vector

Posted: Wed Jun 12, 2013 4:15 pm
by dunne
I'm able to convert a hoc vector to a numpy array using:

Code: Select all

nrnpython("import neuron")
nrnpython("from neuron import h") 
nrnpython("xref = array('d',h.refSTNv)")
But I am unable to convert a numpy array back to hoc. The following code gives me the error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'vec' is not defined
0

Code: Select all

nrnpython("a = [1,2]")
objref vec
vec = new Vector()
nrnpython("vec - vec.from_python(a)")
I also tried using the methods presented by Hines et al. on page 7 of NEURON and Python:

Code: Select all

nrnpython("vec = h.Vector(a)")
which yielded the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Vector'
0

Any thoughts on this? I'm running Neuron version 7.3 with python embedded as an alternative interpreter to hoc.

Re: Numpy array to hoc vector

Posted: Fri Jun 14, 2013 10:45 am
by hines
nrnpython("vec - vec.from_python(a)")
vec on the right side needs to be h.vec since vec from earllier statements was declared in the hoc world. The above will create a 'vec' reference in the python world.

Re: Numpy array to hoc vector

Posted: Wed Jun 19, 2013 12:06 pm
by dunne
That solved the problem. Thank you!