[Numpy-discussion] trim_zeros in more than one dimension?

Robert Kern robert.kern at gmail.com
Sun Apr 25 17:17:11 EDT 2010


On Thu, Apr 22, 2010 at 16:23, Bruce Southey <bsouthey at gmail.com> wrote:
> On 04/21/2010 02:45 PM, Robert Kern wrote:
>> On Wed, Apr 21, 2010 at 10:34, Bruce Southey<bsouthey at gmail.com>  wrote:

>>> 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.
>>
> In such cases you can use the sum of the absolute value of the array or
> the sum of a suitability constructed boolean indicator for the selected
> axis. In the case of floating point dtypes, compare it to a value near
> zero rather than exactly zero.

Or you can use numpy.nonzero(...).any().

-- 
Robert Kern

"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 mailing list