[Numpy-discussion] Re: Record array dimension
Jin-chung Hsu
hsu at stsci.edu
Wed Mar 16 08:41:18 CST 2005
> I was surprised to find out that when I read a field from file into a record
> array with format string "8f4" the corresponding field has dimension (1,8)
> and not (8,) that I would intuitively expect. Am I possibly spesifying the
> format incorrectly? If not, why is there an extra dimension?
The first dimension(s) in a record array is always referring to the number of
"rows". So, if you have:
>>> import numarray.records as rec
>>> r=rec.array(formats='f4', shape=8)
>>> r.field(0).shape
(8,)
which will be what you might have expected. But if
>>> r.rec.array(formats='8f4', shape=10)
>>> r.field(0).shape
(10, 8)
I assume you have the shape=1, and that's why you get (1, 8) for the field shape.
You can have complicated tables like:
--> r=rec.array(formats='(4,5)f4', shape=(2,3))
--> r.field(0).shape
(2, 3, 4, 5)
So, the field shape always has the record array's shape as first
dimension(s).
JC Hsu
More information about the Numpy-discussion
mailing list