[Numpy-discussion] assignment to matrix slice in Numeric bug/feature?
Roman Suzi
rnd at onego.ru
Tue May 21 10:20:02 EDT 2002
hello,
I've found that the following fragment of code gives an error while with
other shapes of b there is no problem:
----------------------------
#!/usr/bin/python2
from Numeric import *
from Matrix import *
a = Matrix(zeros([4,4]))
b = Matrix(ones([2,1]))
print a, a.shape
print b, b.shape
q = a[1:3,1:2]
print q, q.shape
a[1:3,1:2] = b
-----------------------------
resulting in:
-------------------------------------
Matrix([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]) (4, 4)
Matrix([[1],
[1]]) (2, 1)
Matrix([[0],
[0]]) (2, 1)
Traceback (most recent call last):
File "./numpybug.py", line 11, in ?
a[1:3,1:2] = b
File "/usr/lib/python2.1/site-packages/Numeric/Matrix.py", line 180, in
__setitem__
def __setitem__(self, index, value): self.array[index] =
asarray(squeeze(value),self._typecode)
ValueError: matrices are not aligned for copy
-----------------------------------------------
The mentioned behaviour looks like a bug, because
a[1:3,1:2] and b have the same shape and according to docs
b must be copied to a-slice 1:1...
Numeric is version 21.0, Python 2.1 under Linux RedHat 7.2.
Thank you in advance!
Sincerely yours, Roman Suzi
--
\_ Russia \_ Karelia \_ Petrozavodsk \_ rnd at onego.ru \_
\_ Saturday, May 18, 2002 \_ Powered by Linux RedHat 7.2 \_
More information about the NumPy-Discussion
mailing list