Array manipulation
Hi, I would like to remove the i-th column and row from a two-dimensional array A. The remaining array should be kept and stored in B A = random.rand(n,n) This task is very easy if i is the first or last row/column. In that case one can use B = A[1:,1:] or B=A[:-1,:-1] But, what is the best way to get B if 0 < i < n-1 ? Nils
On Wed, Feb 14, 2007 at 09:02:34AM +0100, Nils Wagner wrote:
Hi,
I would like to remove the i-th column and row from a two-dimensional array A. The remaining array should be kept and stored in B
A = random.rand(n,n)
This task is very easy if i is the first or last row/column. In that case one can use
B = A[1:,1:]
or
B=A[:-1,:-1]
But, what is the best way to get B if 0 < i < n-1 ?
numpy.delete(x, i, 1) Cheers Stéfan
Stefan van der Walt wrote:
On Wed, Feb 14, 2007 at 09:02:34AM +0100, Nils Wagner wrote:
Hi,
I would like to remove the i-th column and row from a two-dimensional array A. The remaining array should be kept and stored in B
A = random.rand(n,n)
This task is very easy if i is the first or last row/column. In that case one can use
B = A[1:,1:]
or
B=A[:-1,:-1]
But, what is the best way to get B if 0 < i < n-1 ?
numpy.delete(x, i, 1)
Cheers Stéfan _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
Hi Joris and Stefan, Thank you for your replies. It's nice to see that there are different ways to realize this task. BTW, "insert" is missing in http://www.scipy.org/Numpy_Example_List. I forgot my password to access the wiki page. Joris, please can you add an example for insert. I saw that you have just edited that page. Thanks in advance. Cheers Nils
participants (2)
-
Nils Wagner -
Stefan van der Walt