<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 24, 2015 at 3:46 AM, Robert Kern <span dir="ltr"><<a href="mailto:robert.kern@gmail.com" target="_blank">robert.kern@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On Wed, Jul 22, 2015 at 7:45 PM, <<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>> wrote:<br>><br>> Is there an explanation somewhere of what different basic dtypes mean, across platforms and python versions?<br>><br>> >>> np.bool8<br>> <type 'numpy.bool_'><br>> >>> np.bool_<br>> <type 'numpy.bool_'><br>> >>> bool<br>> <type 'bool'><br>><br>><br>> Are there any rules and recommendations or is it all folks lore?<br><br></span>This may help a little:<div><br></div><div><a href="http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing" target="_blank">http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html#arrays-dtypes-constructing</a></div><div><br></div><div>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.</div><div><br></div><div>See here for why the aliases to Python builtin types, <a href="http://np.int" target="_blank">np.int</a>, np.float, etc. still exist:</div><div><br></div><div><a href="https://github.com/numpy/numpy/pull/6103#issuecomment-123652497" target="_blank">https://github.com/numpy/numpy/pull/6103#issuecomment-123652497</a><br><br>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.<br></div></div></blockquote><div><br></div><div><br></div><div>(I don't have time to follow up on this for at least two weeks)</div><div><br></div><div>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.</div><div>If np.float is always float64 it could be mapped to that directly.</div><div><br></div><div>As the previous discussion on python int versus numpy int on python 3.x, int is at least confusing.</div><div><br></div><div>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 <a href="http://np.int">np.int</a> would be riskier?)</div><div><br></div><div>Josef</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br>--<br>Robert Kern</div></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div></div>