Hi Nils, It's not a one-liner, but it may serve you: In [40]: n = 4 In [41]: i = 2 In [42]: In [42]: A = arange(n*n).reshape(n,n) In [43]: A Out[43]: array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) In [44]: I = range(n) In [45]: I.remove(i) In [46]: B = A[ix_(I,I)] In [47]: B Out[47]: array([[ 0, 1, 3], [ 4, 5, 7], [12, 13, 15]]) Cheers, Joris On Wednesday 14 February 2007 09:02, 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 ?
Nils
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
participants (1)
-
joris@ster.kuleuven.ac.be