Hi there,(adsbygoogle = window.adsbygoogle || []).push({});

I have 1024,1024 arrays (lots of them) which are really roughly 600,800 (it changes) and then buffered by zeros all the way around something like

000000000000000000

000000000000000000

000xxxxxxxxxxxxx000

000xxxxxxxxxxxxx000

000xxxxxxxxxxxxx000

000000000000000000

000000000000000000

i want to delete all the zeros

i can use numpy.all then numpy.delete but i can only make it work with 4 while loops... essentially one from each direction and its just long and untidy.

i can empty all the 0 elements with trim_zeros but then cant find a nice neat way to delete them.

I havnt tried boolean masking yet since i need the element values.

ideas?

thanks

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python Removing 0's from 2d arrays

Have something to add?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**