<div dir="ltr">I have an array of floats and<div>want their floor values as integers.</div><div>(e.g. to use them as indexes for a table lookup)</div><div><br></div><div>It seems reasonable to assume this is</div><div>a frequent use of floor.</div><div><br></div><div>Anyway, you gave me a better vay to do it:</div><div>>>> myints = n.floor(myarray).astype(<a href="http://n.int">n.int</a>)</div><img src="http://t.sidekickopen16.com/e1t/o/5/f18dQhb0S7ks8dDMPbW2n0x6l2B9gXrN7sKj6v5dfcjVRbJkd7dK_XRW2BV_0v2zlZNzW2C2c_41k1H6H0?si=5478613303427072&pi=13adbc1f-d66f-41d4-a400-ee4409781bd9&ti=undefined" style="display:none!important" height="1" width="1"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 25, 2017 at 7:23 AM, Thomas Jollans <span dir="ltr"><<a href="mailto:tjol@tjol.eu" target="_blank">tjol@tjol.eu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2017-09-25 10:59, Renato Fabbri wrote:<br>
> """<br>
> In [3]: n.floor(n.linspace(0,5,7), dtype=<a href="http://n.int" rel="noreferrer" target="_blank">n.int</a> <<a href="http://n.int" rel="noreferrer" target="_blank">http://n.int</a>>)<br>
<span class="">> ------------------------------<wbr>------------------------------<wbr>---------------<br>
> TypeError                                 Traceback (most recent call last)<br>
> <ipython-input-3-1471f5d738e8> in <module>()<br>
</span>> ----> 1 n.floor(n.linspace(0,5,7), dtype=<a href="http://n.int" rel="noreferrer" target="_blank">n.int</a> <<a href="http://n.int" rel="noreferrer" target="_blank">http://n.int</a>>)<br>
<span class="">><br>
> TypeError: No loop matching the specified signature and casting<br>
> was found for ufunc floor<br>
><br>
> In [4]: n.__version__<br>
> Out[4]: '1.11.0'<br>
> """<br>
><br>
> Is this the expected behavior?<br>
<br>
</span>Yes. There is no floor function for integers.<br>
<br>
The dtype argument specified not only the return type, but the type the<br>
calculation is done in as well. floor() only exists, and only makes<br>
sense, for floats. (You can use floor(a, dtype='f4') and so on to insist<br>
on floats of a different width)<br>
<br>
If you have some floats, and you want to get their floor as integers,<br>
you'll have to cast. In that case, in actual fact, there is little<br>
reason to use floor at all:<br>
<br>
In [2]: np.arange(1.9, 11.)<br>
Out[2]: array([  1.9,   2.9,   3.9,   4.9,   5.9,   6.9,   7.9,   8.9,<br>
9.9,  10.9])<br>
<br>
In [3]: np.arange(1.9, 11.).astype('i8')<br>
Out[3]: array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])<br>
<br>
<br>
><br>
> I am doing:<br>
>>>> myints = n.array(n.floor(myarray), dtype=<a href="http://n.int" rel="noreferrer" target="_blank">n.int</a> <<a href="http://n.int" rel="noreferrer" target="_blank">http://n.int</a>>)<br>
<span class="">> to get the integers.<br>
><br>
> tx.<br>
> R.<br>
><br>
><br>
> --<br>
> Renato Fabbri<br>
> GNU/Linux User #479299<br>
</span>> <a href="http://labmacambira.sourceforge.net" rel="noreferrer" target="_blank">labmacambira.sourceforge.net</a> <<a href="http://labmacambira.sourceforge.net" rel="noreferrer" target="_blank">http://labmacambira.<wbr>sourceforge.net</a>><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org">NumPy-Discussion@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/numpy-<wbr>discussion</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Thomas Jollans<br>
______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/numpy-<wbr>discussion</a><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Renato Fabbri</div><div>GNU/Linux User #479299</div><div><a href="http://labmacambira.sourceforge.net" target="_blank">labmacambira.sourceforge.net</a></div></div></div></div></div></div></div></div></div>
</div></div>