Numeric question

Cameron Hooper cameron at hooper.net
Thu Apr 25 21:32:04 EDT 2002


Hi,

I hope someone can help me with this problem. It relates to the
Numeric extension. The code below will fail when calling the
'outerproduct()' procedure:

---------------------------------------------------------
# test.py

from Numeric import *

inputs = array( [[1., 1.],
                 [1., 0.],
                 [0., 1.],
                 [0.,0.]] )


binput = ones((4,1), Float)
inputs = concatenate( (inputs, binput), 1 )

x = inputs[0][:]
t = array([1.])

# this step fails
print outerproduct(x,t)

---------------------------------------------------------

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

However, if I do not use the concatenate procedure to create the input
array then all works perfectly:

----------------------------------------------------------
# test2.py

from Numeric import *

inputs = array( [[1., 1.,1.],
                 [1., 0.,1.],
                 [0., 1.,1.],
                 [0.,0.,1.]] )


x = inputs[0][:]
t = array([1.])

print outerproduct(x,t)

--------------------------------------------------------

The shape of inputs is identical under both programs: shape(inputs) =
(4,3). 

Can anyone see what's going wrong.

Thanks,

Cameron



More information about the Python-list mailing list