Numeric question

Emile van Sebille emile at fenx.com
Thu Apr 25 22:17:28 EDT 2002


Cameron Hooper
> The error produced is:
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/tmp/python-25603Vd", line 21, in ?
>     print outerproduct(x,t)
>   File "/usr/lib/python2.1/site-packages/Numeric/Numeric.py", line
359,
>      in outerproduct return
asarray(a).flat[:,NewAxis]*asarray(b).flat[NewAxis,:]
> ValueError: flattened indexing only available for contiguous array
>

This tells you the problem.  Something is not contiguous.

>>> t.iscontiguous()
1
>>> x.iscontiguous()
0

OK.  It's x.  So let's build a contiguous x and try it again:


>>> from Numeric import *
>>>
>>> inputs = array( [[1., 1.],
...                  [1., 0.],
...                  [0., 1.],
...                  [0.,0.]] )
>>>
>>>
>>> binput = ones((4,1), Float)
>>> inputs = concatenate( (inputs, binput), 1 )
>>>
>>> x = array(inputs[0][:])
>>> t = array([1.])
>>>
>>> # this step fails
... print outerproduct(x,t)
[[ 1.]
 [ 1.]
 [ 1.]]

Not anymore... ;-)

HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list