[Numpy-discussion] Best representation for array of points, or, how to distinguish a Nx1 array of points from a Nx3 array of scalars
Edson Tadeu
e.tadeu@gmail....
Thu Oct 4 07:55:08 CDT 2007
I've found that there are two ways to represent an array of 3D points:
# 01:
N = 4
a = numpy.zeros((N, 3), dtype='f8')
# 02:
N = 4
b = numpy.zeros(N, dtype='3f8')
The second representation seems "conceptually" better, it is really an 1D
array of N elements ( i.e., b.shape == (4,) ), but, "in practice", it is not
very useful, because I can't directly add it to scalar, or to another array
of points, and I can't multiply it by a transformation matrix. With the
first representation, I can use expressions like this:
c = (a+1) * numpy.matrix([[1,0,0],[0,0,3],[0,2,0]]) - numpy.array([1, 5.5,
0])
So, I chose the second representation for my application; the problem is
that its shape is (N, 3), and I haven't found a way to distinguish it from a
Nx3 array of scalars, for example. This distinction is needed, because I
must convert it to other array types (from other libraries), I must make
proper I/O of the array, etc. Also, my application uses 2D and 3D arrays,
and they can be arrays of scalars, of points or of small matrices... so, for
example, a 10x7 array of 2x2 matrices of double is represented in numpy as a
10x7x2x2 array of f8 (without the proper information, it could be viewed
also as a 10x7x2 array of 2D points or a 10x7x2x2 array of doubles, and I
DON'T want this). My question is:
* Is there any field in the NumPy object where I can keep this information
(the shape of the "element"), without creeping it with the dtype='(M,N)f8'
representation I explained above?
Thanks,
Edson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071004/3cff9091/attachment.html
More information about the Numpy-discussion
mailing list