[NumPy-Tickets] [NumPy] #1914: Delayed ValueError when using count_nonzero with object array
NumPy Trac
numpy-tickets@scipy....
Mon Aug 15 12:07:12 CDT 2011
#1914: Delayed ValueError when using count_nonzero with object array
----------------------------------+-----------------------------------------
Reporter: rcl33 | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: numpy.core | Version: 1.6.0
Keywords: object count_nonzero |
----------------------------------+-----------------------------------------
Changes (by rgommers):
* milestone: 1.6.2 => Unscheduled
Comment:
The problem seems to occur when an object array holds a numpy array as an
element.
{{{
>>> x = numpy.zeros((3,), dtype=numpy.object)
>>> x[0] = np.zeros(30)
>>> x
------------------------------------------------------------
Traceback (most recent call last):
...
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
}}}
This works as expected:
{{{
>>> >>> x = numpy.zeros((3,), dtype=numpy.object)
>>> >>> x[0] = 'abcd'
>>> >>> x
array([abcd, 0, 0], dtype=object)
>>> x[0] = {'a' : 1, 'b' : 2} # with a sequence also OK
>>> x
array([{'a': 1, 'b': 2}, 0, 0], dtype=object)
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1914#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list