Discussion:
[Numpy-discussion] difference between dtypes
j***@gmail.com
2015-07-22 18:45:43 UTC
Permalink
Is there an explanation somewhere of what different basic dtypes mean,
across platforms and python versions?
np.bool8
<type 'numpy.bool_'>
np.bool_
<type 'numpy.bool_'>
bool
<type 'bool'>


Are there any rules and recommendations or is it all folks lore?


I'm asking because my intuition picked up by osmosis might be off, and I
thought
https://github.com/scipy/scipy/pull/5076
is weird (i.e. counter intuitive).


Deprecation warnings are always a lot of fun, especially if
"This log is too long to be displayed. Please reduce the verbosity of your
build or download the raw log."

Josef
Robert Kern
2015-07-24 07:46:53 UTC
Permalink
Post by j***@gmail.com
Is there an explanation somewhere of what different basic dtypes mean,
across platforms and python versions?
Post by j***@gmail.com
np.bool8
<type 'numpy.bool_'>
np.bool_
<type 'numpy.bool_'>
bool
<type 'bool'>
Are there any rules and recommendations or is it all folks lore?
This may help a little:

http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing

Basically, we accept the builtin Python type objects as a dtype argument
and do something sensible with them. float -> np.float64 because Python
floats are C doubles. int -> np.int32 or np.int64 depending on whatever a C
long is (i.e. depending on the 64bitness of your CPU and how your OS
chooses to deal with that). We encode those precision choices as aliases to
the corresponding specific numpy scalar types (underscored as necessary to
avoid shadowing builtins of the same name): np.float_ is np.float64, for
example.

See here for why the aliases to Python builtin types, np.int, np.float,
etc. still exist:

https://github.com/numpy/numpy/pull/6103#issuecomment-123652497

If you just need to pass a dtype= argument and want the precision that
matches the "native" integer and float for your platform, then I prefer to
use the Python builtin types instead of the underscored aliases; they just
look cleaner. If you need a true numpy scalar type (e.g. to construct a
numpy scalar object), of course, you must use one of the numpy scalar
types, and the underscored aliases are convenient for that. Never use the
aliases to the Python builtin types.

--
Robert Kern
j***@gmail.com
2015-07-24 09:05:41 UTC
Permalink
Post by j***@gmail.com
Post by j***@gmail.com
Is there an explanation somewhere of what different basic dtypes mean,
across platforms and python versions?
Post by j***@gmail.com
np.bool8
<type 'numpy.bool_'>
np.bool_
<type 'numpy.bool_'>
bool
<type 'bool'>
Are there any rules and recommendations or is it all folks lore?
http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing
Basically, we accept the builtin Python type objects as a dtype argument
and do something sensible with them. float -> np.float64 because Python
floats are C doubles. int -> np.int32 or np.int64 depending on whatever a C
long is (i.e. depending on the 64bitness of your CPU and how your OS
chooses to deal with that). We encode those precision choices as aliases to
the corresponding specific numpy scalar types (underscored as necessary to
avoid shadowing builtins of the same name): np.float_ is np.float64, for
example.
See here for why the aliases to Python builtin types, np.int, np.float,
https://github.com/numpy/numpy/pull/6103#issuecomment-123652497
If you just need to pass a dtype= argument and want the precision that
matches the "native" integer and float for your platform, then I prefer to
use the Python builtin types instead of the underscored aliases; they just
look cleaner. If you need a true numpy scalar type (e.g. to construct a
numpy scalar object), of course, you must use one of the numpy scalar
types, and the underscored aliases are convenient for that. Never use the
aliases to the Python builtin types.
(I don't have time to follow up on this for at least two weeks)

my thinking was that, if there is no actual difference between bool,
np.bool and np.bool_, the np.bool could become an alias and a replacement
for np.bool_, so we can get rid of a "ugly" trailing underscore.
If np.float is always float64 it could be mapped to that directly.

As the previous discussion on python int versus numpy int on python 3.x,
int is at least confusing.

Also I'm thinking that maybe adjusting the code to the (mis)interpretation,
instead of adjusting killing np.float completely might be nicer, (but
changing np.int would be riskier?)

Josef
Post by j***@gmail.com
--
Robert Kern
_______________________________________________
NumPy-Discussion mailing list
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Robert Kern
2015-07-24 10:47:05 UTC
Permalink
Post by j***@gmail.com
Post by Robert Kern
Post by j***@gmail.com
Is there an explanation somewhere of what different basic dtypes mean,
across platforms and python versions?
Post by j***@gmail.com
Post by Robert Kern
Post by j***@gmail.com
np.bool8
<type 'numpy.bool_'>
np.bool_
<type 'numpy.bool_'>
bool
<type 'bool'>
Are there any rules and recommendations or is it all folks lore?
http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing
Post by j***@gmail.com
Post by Robert Kern
Basically, we accept the builtin Python type objects as a dtype argument
and do something sensible with them. float -> np.float64 because Python
floats are C doubles. int -> np.int32 or np.int64 depending on whatever a C
long is (i.e. depending on the 64bitness of your CPU and how your OS
chooses to deal with that). We encode those precision choices as aliases to
the corresponding specific numpy scalar types (underscored as necessary to
avoid shadowing builtins of the same name): np.float_ is np.float64, for
example.
Post by j***@gmail.com
Post by Robert Kern
See here for why the aliases to Python builtin types, np.int, np.float,
https://github.com/numpy/numpy/pull/6103#issuecomment-123652497
If you just need to pass a dtype= argument and want the precision that
matches the "native" integer and float for your platform, then I prefer to
use the Python builtin types instead of the underscored aliases; they just
look cleaner. If you need a true numpy scalar type (e.g. to construct a
numpy scalar object), of course, you must use one of the numpy scalar
types, and the underscored aliases are convenient for that. Never use the
aliases to the Python builtin types.
Post by j***@gmail.com
(I don't have time to follow up on this for at least two weeks)
my thinking was that, if there is no actual difference between bool,
np.bool and np.bool_, the np.bool could become an alias and a replacement
for np.bool_, so we can get rid of a "ugly" trailing underscore.
Post by j***@gmail.com
If np.float is always float64 it could be mapped to that directly.
Well, I'll tell you why that's a bad idea in when you get back in two weeks.

--
Robert Kern

Loading...