Numpy array to hoc vector

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
dunne
Posts: 2
Joined: Tue May 07, 2013 10:36 am

Numpy array to hoc vector

Post by dunne » Wed Jun 12, 2013 4:15 pm

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.

hines
Site Admin
Posts: 1575
Joined: Wed May 18, 2005 3:32 pm

Re: Numpy array to hoc vector

Post by hines » Fri Jun 14, 2013 10:45 am

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.

dunne
Posts: 2
Joined: Tue May 07, 2013 10:36 am

Re: Numpy array to hoc vector

Post by dunne » Wed Jun 19, 2013 12:06 pm

That solved the problem. Thank you!

Post Reply