[Numpy-discussion] bug in array instanciation?
Robert Kern
robert.kern@gmail....
Fri Jan 27 15:22:31 CST 2012
On Fri, Jan 27, 2012 at 21:17, Emmanuel Mayssat <emayssat@gmail.com> wrote:
> In [20]: dt_knobs =
> [('pvName',(str,40)),('start','float'),('stop','float'),('mode',(str,10))]
>
> In [21]: r_knobs = np.recarray([],dtype=dt_knobs)
>
> In [22]: r_knobs
> Out[22]:
> rec.array(('\xa0\x8c\xc9\x02\x00\x00\x00\x00(\xc8v\x02\x00\x00\x00\x00\x00\xd3\x86\x02\x00\x00\x00\x00\x10\xdeJ\x02\x00\x00\x00\x00\x906\xb9\x02',
> 1.63e-322, 1.351330465085e-312, '\x90\xc6\xa3\x02\x00\x00\x00\x00P'),
> dtype=[('pvName', '|S40'), ('start', '<f8'), ('stop', '<f8'),
> ('mode', '|S10')])
>
> why is the array not empty?
The shape [] creates a rank-0 array, which is essentially a scalar.
[~]
|1> x = np.array(10)
[~]
|2> x
array(10)
[~]
|3> x.shape
()
If you want an empty array, you need at least one dimension of size 0:
[~]
|7> r_knobs = np.recarray([0], dtype=dt_knobs)
[~]
|8> r_knobs
rec.array([],
dtype=[('pvName', '|S40'), ('start', '<f8'), ('stop', '<f8'),
('mode', '|S10')])
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list