[Numpy-discussion] Suppressing "nesting" (recursion, descent) in array construction.
Michael McNeil Forbes
mforbes@physics.ubc...
Thu Jun 21 08:24:30 CDT 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