[Numpy-discussion] Incorrect result when multiplying views of record arrays

Albert Strasheim fullung at gmail.com
Mon May 8 10:51:51 EDT 2006


Hello all

I've found a possible bug when multiplying views of record arrays. Strangely
enough, this only shows up on Linux. Luckily, the unit tests for my library
picked up on this.

The code:

import numpy as N      
rdt = N.dtype({'names' : ['i', 'j'], 'formats' : [N.intc, N.float64]})

x = N.array([[(1,5.),(2,6.),(-1,0.)]], dtype=rdt)
y = N.array([[(1,1.),(2,2.),(-1,0.)],
             [(1,3.),(2,4.),(-1,0.)]],
            dtype=rdt)           
xv = x['j'][:,:-1]
yv = y['j'][:,:-1]
z = N.dot(yv, N.transpose(xv))

The operands:

yv =
[[ 1.  2.]
 [ 3.  4.]]
xv = 
[[ 5.  6.]]
z =
[[  5.]
 [ 15.]]

The expected result is [[17, 39]]', which is what I get on Windows. If I
copy the views prior to multiplying:

a = N.array(xv)
b = N.array(yv)
c = N.dot(b, N.transpose(a))

I get the correct result on both platforms.

Trac ticket at http://projects.scipy.org/scipy/numpy/ticket/98.

Cheers,

Albert





More information about the NumPy-Discussion mailing list