faqts : Computers : Programming : Languages : Python : Modules : numpy

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

8 of 11 people (73%) answered Yes
Recently 2 of 4 people (50%) answered Yes

Entry

Is there a general way to remove axes of length 1? eg. I have an array of shape (1,3,1,4) I want to change it to (3,4)?

Jun 13th, 2000 20:30
unknown unknown, Konrad Hinsen


For a specific known shape, just assign a new one:

 array.shape = (3, 4)

For suppressing all axes of length one, no matter where, you can write

 array.shape = Numeric.repeat(array.shape, 
Numeric.not_equal(array.shape, 1))

Note that this changes the array, it does not create a new one.