[Numpy-discussion] trim_zeros in more than one dimension?
Wed Apr 21 14:45:17 CDT 2010
On Wed, Apr 21, 2010 at 10:34, Bruce Southey <email@example.com> wrote:
> On 04/21/2010 08:36 AM, Robert Kern wrote:
>> On Tue, Apr 20, 2010 at 18:45, Charles R Harris
>> <firstname.lastname@example.org> wrote:
>>> On Tue, Apr 20, 2010 at 7:03 AM, Andreas Hilboll<email@example.com> wrote:
>>>> Hi there,
>>>> is there an easy way to do something like trim_zeros() does, but for a
>>>> n-dimensional array? I have a 2d array with only zeros in the first and
>>>> last rows and columns, and would like to trim this array to only the
>>>> non-zero part ...
>>> I think for your application it would be easier to use a subarray, something
>>> like a[1:-1, 1:-1].
>> Yes, but I think he's asking for a function that will find the
>> appropriate slices for him, justl like trim_zeros() does for 1D
> If the sum of axis to be removed equals zero then you can conditionally
> remove that axis.
No. Negative numbers can cancel out positive numbers.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion