[Numpy-discussion] Bug or feature?
Travis Oliphant
teoliphant@gmail....
Mon Aug 22 07:50:06 CDT 2011
This goes into the category of "feature". Structured arrays use tuples to indicate a record. So, (only) when using structured arrays as a dtype, there is a difference between lists and tuples. In this case, array sees the tuple and expects it to have 2 elements to match the number of fields in 2.
Best,
-Travis
On Aug 22, 2011, at 2:36 AM, Konrad Hinsen wrote:
> Hi everyone,
>
> I just stumbled on a behavior in NumPy for which I can't find an
> explanation in the documentation. I wonder whether this is a bug or an
> undocumented (or badly documented) feature:
>
> --------------------------------------------------------------------------------------
> import numpy
>
> t = numpy.dtype([("rotation", numpy.float64, (3, 3)),
> ("translation", numpy.float64, (3,))])
>
> # works
> a1 = numpy.array([], dtype=t)
>
> # doesn't work
> a2 = numpy.array((), dtype=t)
> # -> ValueError: size of tuple must match number of fields.
> --------------------------------------------------------------------------------------
>
> According to my understanding of how numpy.array should work, it
> shouldn't make a difference if the first argument is a list or a
> tuple, but in this case there is a difference.
>
> Konrad.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
---
Travis Oliphant
Enthought, Inc.
oliphant@enthought.com
1-512-536-1057
http://www.enthought.com
More information about the NumPy-Discussion
mailing list