Page 1 of 1

### Using vectors as arguments for pt3dadd

Posted: Mon Mar 02, 2020 3:46 pm
Looking through the documentation for pt3dadd, I see:
h.pt3dadd(xvec, yvec, zvec, dvec, sec=section)
...
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]))
dend.pt3dadd(xvec, yvec, zvec, dvec)
``````
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?

### Re: Using vectors as arguments for pt3dadd

Posted: Tue Mar 03, 2020 8:34 am
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])

h.pt3dadd(x, y, z, d, sec=soma)

for i in range(soma.n3d()):
print(soma.x3d(i), soma.y3d(i), soma.z3d(i), soma.diam3d(i))
``````

### Re: Using vectors as arguments for pt3dadd

Posted: Tue Mar 03, 2020 9:06 pm
Thank you, I will try using that syntax instead!