<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 7, 2015 at 2:45 PM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@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"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Mar 7, 2015 at 2:02 PM, Dinesh Vadhia <span dir="ltr"><<a href="mailto:dineshbvadhia@hotmail.com" target="_blank">dineshbvadhia@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>



<div style="PADDING-LEFT:10px;PADDING-RIGHT:10px;PADDING-TOP:15px" name="Compose message area">
<div><font face="Garamond" size="4">
<div><font face="Garamond" size="4">This was originally posted on SO (<a title="https://stackoverflow.com/questions/28853740/numpy-array-casting-ruled-not-safe
CTRL + Click to follow link">https://stackoverflow.com/questions/28853740/numpy-array-casting-ruled-not-safe</a>) 
and it was suggested it is probably a bug in numpy.take.</font></div>
<div><font face="Garamond" size="4"></font> </div>
<div><font face="Garamond" size="4">Python 2.7.8 |Anaconda 2.1.0 (32-bit)| (default, 
Jul  2 2014, 15:13:35) [MSC v.1500 32 bit (Intel)] on win32<br>Type 
"copyright", "credits" or "license()" for more information.</font></div>
<div><font face="Garamond" size="4"><br>>>> import numpy<br>>>> 
numpy.__version__<br>'1.9.2'</font></div>
<div> </div>
<div><font face="Garamond" size="4">>>> a = numpy.array([9, 7, 5, 4, 3, 1], 
dtype=numpy.uint32)<br>>>> b = numpy.array([1, 3], 
dtype=numpy.uint32)<br>>>> c = a.take(b)</font></div>
<div> </div>
<div><font face="Garamond" size="4">Traceback (most recent call last):<br>  
File "<pyshell#5>", line 1, in <module><br>    c = 
a.take(b)<br>TypeError: Cannot cast array data from dtype('uint32') to 
dtype('int32') according to the rule 'safe'</font></div></font></div></div></blockquote><div><br></div></div></div><div><font>This actually looks correct for 32-bit windows. Numpy indexes with a signed type big enough to hold a pointer to void, which in this case is an int32, and the uint32 cannot be safely cast to that type.<br><br></font></div><div><font>Chuck<br></font></div></div></div></div></blockquote><div><br></div><div><font>I note that on SO Jaime made the suggestion that take use unsafe casting and throw an error on out of bounds indexes. That sounds reasonable, although for sufficiently large integer types an index could wrap around to a good value. Maybe make it work only for npy_uintp.<br><br></font></div><div><font>Chuck  <br></font></div></div><br></div></div>