[SciPy-dev] 'O' type arrays and containers as values...
oliphant at ee.byu.edu
Fri Nov 4 15:00:51 CST 2005
Fernando Perez wrote:
>If I understand things correctly, the following should work fine:
>In : import scipy
>In : scipy.__core_version__
>In : a=scipy.empty((2,2),'O')
>In : a[0,0] = (1,2,3)
The problem here is the ambiguity of the left hand side and how
assignment is generally done. There is no special-check for this
case. All that happens is that (1,2,3) gets converted to an object
array and the elements copied over. So, you are trying to do the
a[0,0] = array((1,2,3),'O')
But, the right-hand side is converted to a length-3 object array ---
with container types it's ambiguous as to what you really want for the
Then of course the length-3 array cannot be copied into the result.
Now, one solution is to special-case the PyArrayObject assignment and
check for single-index assigment and just copy whatever the value is
directly over. Of course the more special-cases, the slower all code
This has always been a problem. You would get a similar error in Numeric.
More information about the Scipy-dev