[Numpy-discussion] overlapping rows
Matthew Koichi Grimes
mkg@cs.nyu....
Wed Mar 7 15:54:01 CST 2007
I would like to twiddle with the strides of a matrix such that the rows
overlap each other. I've gotten this far:
In [1]: import numpy as N
In [2]: mat = N.arange(12).reshape(3,4)
In [3]: mat
Out[3]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
In [4]: mat.strides
Out[4]: (16, 4)
In [5]: omat = mat[...]
In [6]: omat.strides = (8,4)
In [7]: omat
Out[7]:
array([[0, 1, 2, 3],
[2, 3, 4, 5],
[4, 5, 6, 7]])
So far so good, but I'd like to have "omat"'s first dimension grow to
size 6 so that all of the data is used. In other words, I'd like for
omat to look like:
array([[0, 1, 2, 3],
[2, 3, 4, 5],
[4, 5, 6, 7],
[6, 7, 8, 9],
[8, 9, 10, 11]])
However, when I try to resize the first dimension to 6 I get the
following error:
In [8]: omat.shape = (6,4)
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/home/mkg/<ipython console>
ValueError: total size of new array must be unchanged
Is there any workaround to this? It seems like something I should be
able to do, since I'm only growing omat into memory that's owned
by omat.base.
Any help would be much appreciated,
-- Matt
More information about the Numpy-discussion
mailing list