[Numpy-discussion] trim_zeros in more than one dimension?
Robert Kern
robert.kern@gmail....
Sun Apr 25 16:18:31 CDT 2010
On Sun, Apr 25, 2010 at 16:17, Robert Kern <robert.kern@gmail.com> wrote:
> On Thu, Apr 22, 2010 at 16:23, Bruce Southey <bsouthey@gmail.com> wrote:
>> On 04/21/2010 02:45 PM, Robert Kern wrote:
>>> On Wed, Apr 21, 2010 at 10:34, Bruce Southey<bsouthey@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().
Or really just .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