[Numpy-discussion] Problems with creating arrays from array descriptors and lists
Travis Oliphant
oliphant.travis at ieee.org
Mon Jan 30 09:26:07 EST 2006
Francesc Altet wrote:
>El dl 30 de 01 del 2006 a les 02:23 -0700, en/na Travis Oliphant va
>escriure:
>
>
>>>In [20]:numpy.array([1,1], dtype=[('f1', 'i8'),('f2','i4')])
>>>---------------------------------------------------------------------------
>>>exceptions.TypeError Traceback (most
>>>recent call last)
>>>
>>>/home/faltet/<ipython console>
>>>
>>>TypeError: expected a readable buffer object
>>>
>>>Sorry, I cannot check with latest SVN because it segfaults.
>>>
>>>
>>>
>>>
>>It shouldn't. Latest SVN works fine.
>>
>>
>
>True.
>
>
>
>>But, your example does not work (Records are only settable with tuples).
>>
>>numpy.array((1,1), ....) would work (returning an 0-d array)
>>
>>
>
>Why is this? I think that allowing lists as well would be highly useful.
>In fact, I'm sure that many users are more used to provide lists instead
>of tuples. Moreover, allowing tuples and not lists can be a bit
>misleading, IMO.
>
>
You can provide lists. It's just that fields must be entered in the
array constructor as tuples to fill them in. This was the easiest to
implement (it fit in naturally with the code already written from
Numeric, and does not seem to me to be a real limitation and in fact can
make things more readable.
Thus, you can do
numpy.array([[obj1, obj2, obj3]], dtype=<withfields>)
as long as the objects are tuples.
-Travis
More information about the NumPy-Discussion
mailing list