[SciPy-user] [newbie] array cloning with new size
Mauro Cherubini
martigan at gmail.com
Mon Oct 24 06:19:35 CDT 2005
Dear All,
sorry for the silly question, but I am struggling with the following
problem:
I have to clone a 2D array into another 2D array with an extra empty
line. Then I want to copy the first line of the array into the empty
last line of the array.
I tried a couple of things to get it sorted but none of them worked.
The last attempt is reported below (my matrix has three columns),
where I used the resize() function, which throws back this error from
scipy:
...
File "/Users/mauro/Documents/workspace/tag-wai/
TagsNetworkMaker.py", line 52, in matrix_preparator
new_matrix = resize(datamatrix, [lato +1, 3])
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/site-packages/scipy/base/oldnumeric.py", line 196, in resize
total_size = up.multiply.reduce(new_shape)
NameError: global name 'up' is not defined
By the way, can anyone explain me how to slice and assign a submatrix
from the original matrix? I tried this syntax with no luck:
new_matrix[: lato, :] = datamatrix[:, :]
Thanks a lot in advance for your hints
Mauro
MY LAST ATTEMPT:
----------------------------
# the following method should prepare the matrix for the
processing. In fact, we need to have a poligon set of points
# which is by definition closed so the first point should be
added into the matrix as last point
def matrix_preparator(self, datamatrix):
# first we find the number of points in the matrix
lato = datamatrix.shape[0]
# if the matrix contains only one row then it exit
if lato > 1:
# now we create a new matrix with an extra line
new_matrix = resize(datamatrix, [lato +1, 3])
print new_matrix
# here we clone the first point to the last line
new_matrix[lato + 1, :] = datamatrix[0, :]
# now the matrix is ready for processing
return new_matrix;
else:
return datamatrix;
--
web: http://craft.epfl.ch -- blog: http://www.i-cherubini.it/mauro/blog/
More information about the SciPy-user
mailing list