[Numpy-discussion] Suppressing "nesting" (recursion, descent) in array construction.
Michael McNeil Forbes
mforbes at physics.ubc.ca
Thu Jun 21 09:24:30 EDT 2007
>> key_array = empty(len(keys),dtype=tuple)
>> key_array[:] = keys[:]
>
> the later two statements can also be written as:
>
> key_array = array(keys, dtype=tuple)
These are not equivalent:
>>> keys = [('a',1),('b',2)]
>>> key_array = array(keys, dtype=tuple)
>>> key_array
array([[a, 1],
[b, 2]], dtype=object)
>>> key_array = empty(len(keys),dtype=tuple)
>>> key_array[:] = keys[:]
>>> key_array
array([('a', 1), ('b', 2)], dtype=object)
Thanks,
Michael.
More information about the NumPy-Discussion
mailing list