I
Ivan Vinogradov
Hello All,
this seems like a trivial problem, but I just can't find an elegant
solution neither by myself, nor with google's help.
I'd like to be able to keep an array representing coordinates for a
system of points.
Since I'd like to operate on each point's coordinates individually,
for speed and ufuncs
numarray fits the bill perfectly, especially since system.coordinates
[4] would return proper vector for a 5th point.
To start, read the coordinates from a text file and add them to our
array one by one.
Here it gets un-elegant and probably wasteful for a large number of
points, by converting the whole array to a list only to use append
method and then convert it back to array(sample code below). Also,
there is potential need to add more points later on.
Any pointers would be greatly appreciated.
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/numarray/numarraycore.py", line 417, in array return
fromlist(sequence,type,shape)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/numarray/numarraycore.py", line 267, in fromlist
arr.fromlist(seq)
ValueError: Nested sequences with different lengths.
[0, 0, 3]])
this seems like a trivial problem, but I just can't find an elegant
solution neither by myself, nor with google's help.
I'd like to be able to keep an array representing coordinates for a
system of points.
Since I'd like to operate on each point's coordinates individually,
for speed and ufuncs
numarray fits the bill perfectly, especially since system.coordinates
[4] would return proper vector for a 5th point.
To start, read the coordinates from a text file and add them to our
array one by one.
Here it gets un-elegant and probably wasteful for a large number of
points, by converting the whole array to a list only to use append
method and then convert it back to array(sample code below). Also,
there is potential need to add more points later on.
Any pointers would be greatly appreciated.
File "<stdin>", line 1, in ?>>> from numarray import array
>>> p1 = [0,0,1]
>>> p2 = [0,0,2]
>>> p3 = [0,0,3]
>>> a1 = array((p1,p2))
>>> a1array([[0, 0, 1], [0, 0, 2]])
>>> a2 = array((a1,p3))Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/numarray/numarraycore.py", line 417, in array return
fromlist(sequence,type,shape)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/
site-packages/numarray/numarraycore.py", line 267, in fromlist
arr.fromlist(seq)
ValueError: Nested sequences with different lengths.
[0, 0, 2],>>> temp = list(a1)
>>> temp.append(p3)
>>> a2 = array(temp)
>>> a2array([[0, 0, 1],
[0, 0, 3]])