On Fri, Jan 27, 2012 at 21:17, Emmanuel Mayssat <emays...@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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to