Is a string a scalar?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is a string a scalar?

Keith Goodman
>> np.isscalar('string')
   True
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Is a string a scalar?

Robert Kern-2
On Wed, May 7, 2008 at 3:24 PM, Keith Goodman <[hidden email]> wrote:
> >> np.isscalar('string')
>    True

<shrug> Either option would cause someone to complain. It's not a
cut-and-dry issue. However, since strings can be atomic elements
through the various '|S<N>' dtypes, and we already have rules to
special-case strings as atomic, "numpy.isscalar('string') == False"
would be more inconsistent.

In [1]: from numpy import *

In [2]: array(['one', 'two'])
Out[2]:
array(['one', 'two'],
      dtype='|S3')

--
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
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Is a string a scalar?

Keith Goodman
On Wed, May 7, 2008 at 1:37 PM, Robert Kern <[hidden email]> wrote:
> On Wed, May 7, 2008 at 3:24 PM, Keith Goodman <[hidden email]> wrote:
>  > >> np.isscalar('string')
>  >    True
>
>  <shrug> Either option would cause someone to complain. It's not a
>  cut-and-dry issue. However, since strings can be atomic elements
>  through the various '|S<N>' dtypes, and we already have rules to
>  special-case strings as atomic, "numpy.isscalar('string') == False"
>  would be more inconsistent.

BTW, I noticed that defmatrix.py uses isscalar (from numeric import
isscalar) and N.isscalar (import numpric as N). Each is used only one
time. It confused me a little at first. But that's not saying much.
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Is a string a scalar?

Robert Kern-2
On Wed, May 7, 2008 at 3:58 PM, Keith Goodman <[hidden email]> wrote:

> On Wed, May 7, 2008 at 1:37 PM, Robert Kern <[hidden email]> wrote:
>  > On Wed, May 7, 2008 at 3:24 PM, Keith Goodman <[hidden email]> wrote:
>  >  > >> np.isscalar('string')
>  >  >    True
>  >
>  >  <shrug> Either option would cause someone to complain. It's not a
>  >  cut-and-dry issue. However, since strings can be atomic elements
>  >  through the various '|S<N>' dtypes, and we already have rules to
>  >  special-case strings as atomic, "numpy.isscalar('string') == False"
>  >  would be more inconsistent.
>
>  BTW, I noticed that defmatrix.py uses isscalar (from numeric import
>  isscalar) and N.isscalar (import numpric as N). Each is used only one
>  time. It confused me a little at first. But that's not saying much.

Different authors at different times. It should be cleaned up.

--
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
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion