[Numpy-discussion] silly isscalar question

Derek Homeier derek at astro.physik.uni-goettingen.de
Tue May 29 09:31:23 EDT 2012


On 29 May 2012, at 15:00, Mark Bakker wrote:

> Why does isscalar('hello') return True?
> 
> I thought it would check for a number?

No, it checks for something that is of 'scalar type', which probably can be 
translated as 'not equivalent to an array'. Since strings can form numpy arrays, 
I guess the logic behind this is that the string is the atomic block of an array 
of dtype 'S' - for comparison, np.isscalar(['hello']) = False. 
I note the fine distinction between np.isscalar( ('hello') ) and np.isscalar( ('hello'), )...

Cheers,
						Derek




More information about the NumPy-Discussion mailing list