## Using vectors as arguments for pt3dadd

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

Moderator: hines

neuromau
Posts: 97
Joined: Mon Apr 20, 2009 7:02 pm

### Using vectors as arguments for pt3dadd

Looking through the documentation for pt3dadd, I see:
...
Add the 3d location and diameter point (or points in the second form) at the end of the current pt3d list
...
Note: A more object-oriented approach is to use sec.pt3dclear() instead.
I am struggling with implementing this when I have a list of values for, say, 4 points that I want to add:

Code: Select all

``````from neuron import h, gui
import numpy as np
dend=h.Section(name='dend')
dend.pt3dclear()
xvec=h.Vector(np.array([-0.72,-0.72,-0.72,-0.72]))
yvec=h.Vector(np.array([-16.42,-18.16,-22.14,-24.13]))
zvec=h.Vector(np.array([0.0,0.0,0.0,0.0]))
dvec=h.Vector(np.array([2.4,2.2,2.0,1.96]))
``````
Gives the error
TypeError: must be real number, not hoc.HocObject
I get the same error with:

Code: Select all

``xvec=h.Vector([-0.72,-0.72,-0.72,-0.72])``
While I get other errors when trying the following:

Code: Select all

``````xvec=[-0.72,-0.72,-0.72,-0.72] # gives the error: must be real number, not list

xvec=np.array([-0.72,-0.72,-0.72,-0.72]) # gives the error: TypeError: only size-1 arrays can be converted to Python scalars``````
I'm using Neuron 7.7.2:

Code: Select all

``````print(neuron.version)
7.7.2``````
What am I doing incorrectly when trying to supply vectors instead of scalars as arguments to pt3dadd?
ramcdougal
Posts: 225
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

### Re: Using vectors as arguments for pt3dadd

There are two ways to define 3D points.

The more object-oriented way is to use sections, e.g.

Code: Select all

``````soma.pt3dadd(x, y, z, d)
``````
Unfortunately, that way requires numbers for the arguments.

The older (and, apparently, more flexible in that it supports Vectors) way uses h and requires a sec= argument; in particular, it is not a method of the section:

Code: Select all

``````from neuron import h

soma = h.Section(name='soma')

x = h.Vector([0, 5, 10])
y = h.Vector([0, 0, 0])
z = h.Vector([4, 3, 8])
d = h.Vector([1, 2, 1])