Faqts : Business : Programming : Shopping For You : Python : Modules : numpy

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 3 people (33%) answered Yes
Recently 0 of 2 people (0%) answered Yes

Entry

How do I create a copy an array with specified entries removed (like slicing in reverse)? The Matlab way of doing it is: X1=X0(:,[1:j-1,j+1:p])

Oct 17th, 2009 06:26
adel85 adel85, Dan Schult, Louis Luang,


numpy accepts a list/tuple for slice indices, so if you can create a 
list/tuple of
the specified entries you want, the syntax is very similar to that for 
matlab.

For the example you show, the numpy syntax is:
X1=X0[:, [ i for i in range(p) if i !=j] ]
or perhaps more to your liking:
X1=X0[:, range(j-1)+range(j,p)]

Remember that indices start counting at 0, 
so if j==5 this will remove the 6th column of the array.

As another example, if you only wanted every other row:
X1=X0[ range(0,p,2) , :]

http://www.borsaat.com/vb/f2/
http://www.borsaat.com/vb/f4/
http://www.borsaat.com/vb/f8/
http://www.borsaat.com/vb/f14/
http://www.borsaat.com/vb/f28/
http://www.borsaat.com/vb/f30/
http://www.borsaat.com/vb/f10/
http://www.borsaat.com/vb/f11/
http://www.borsaat.com/vb/f12/
http://www.borsaat.com/vb/f13/
http://www.borsaat.com/vb/f6/
http://www.borsaat.com/vb/f64/
http://www.borsaat.com/vb/f38/
http://www.borsaat.com/vb/f41/
http://www.borsaat.com/vb/f44/
http://www.borsaat.com/vb/f56/
http://www.borsaat.com/vb/f45/
http://www.borsaat.com/vb/f65/
http://www.borsaat.com/vb/f57/
http://www.borsaat.com/vb/f23/
http://www.borsaat.com/vb/f54/
http://www.borsaat.com/vb/f22/
http://www.borsaat.com/vb/f55/
http://www.borsaat.com/vb/f43/
http://www.borsaat.com/vb/f66/
http://www.borsaat.com/vb/f67/
http://www.borsaat.com/vb/f69/
http://www.borsaat.com/vb/f42/
http://www.borsaat.com/vb/f68/
http://www.borsaat.com/vb/f70/
http://www.borsaat.com/vb/f26/
http://www.borsaat.com/vb/
http://www.borsaat.com/vb/f90/