[Numpy-discussion] silly isscalar question
njs at pobox.com
Tue May 29 09:27:32 EDT 2012
On Tue, May 29, 2012 at 2:00 PM, Mark Bakker <markbak at gmail.com> wrote:
> Why does isscalar('hello') return True?
> I thought it would check for a number?
> Numpy 1.6.1
> Silly question?
Nope, but you're thinking of a different sense of "scalar" :-).
In numpy, "scalar" means something like "anything that you can have an
array of". So numbers are scalars, but so are booleans and strings. If
you want to know whether something is a number, I suggest
Though, looking more closely, isscalar returns True for buffer
objects, which can only go into arrays that have dtype=object. But
isscalar returns False for other user-defined types that would go into
a dtype=object array. So perhaps it is a bit confused...
More information about the NumPy-Discussion