[Numpy-discussion] truth value of dtypes
Robert Kern
robert.kern at gmail.com
Fri Dec 10 09:33:40 EST 2010
On Fri, Dec 10, 2010 at 03:13, Nils Becker <n.becker at amolf.nl> wrote:
> Hi,
>
> why is
>
>>>> bool(np.dtype(np.float))
> False
>
> ?
>
> I came across this when using this python idiom:
>
> def f(dtype=None):
> ....if not dtype:
> ........print 'using default dtype'
The default truth value probably should be True, but not for this
reason. The correct idiom to use is this:
def f(dtype=None):
if dtype is None:
print 'using default dtype'
--
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