question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WISH: [option to] make np.floor(), np.ceil(), np.trunc() etc return arrays with dtype=int

See original GitHub issue

I’m trying to plot two quantities against each other but they are sampled at different intervals. I tried plt.plot(array1, array2[np.floor(array1time / array2interval)]). However, np.floor returns a float array so I need to cast the result to an integer type first.

This seems a bit silly. Is there any reason why someone would depend on the result of floor() being a floating point number?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
jennirinkercommented, Nov 12, 2020

In case anyone would like a work-around, you can easily cast to an integer array after floor is called:

import numpy as np
x = np.arange(10) / 2
xfloor_int = np.floor(x).astype(int)  # array of ints
0reactions
chatcannoncommented, Dec 25, 2020

@jennirinker That’s a great suggestion. It does exactly what I originally wanted, is not any more verbose, and doesn’t require any changes to numpy. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Round up/down the elements of a ndarray (np.floor, trunc, ceil)
You can use np.floor() , np.trunc() , np.ceil() , etc. to round up and down the elements of a NumPy array ndarray ....
Read more >
numpy.ceil — NumPy v1.24 Manual
If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to...
Read more >
CuPy Documentation - Read the Docs
CuPy is a NumPy/SciPy-compatible array library for GPU-accelerated computing with Python. CuPy acts as a drop-in.
Read more >
SciPy Reference Guide
Scipy and Numpy have HTML and PDF versions of their documentation ... mer command is array based and returns byte arrays of ones...
Read more >
What's New — pandas 0.23.3 documentation - PyData |
With NumPy 1.15 and pandas 0.23.1 or earlier, numpy.all() will no longer reduce over ... Bug in Timestamp.ceil() and Timestamp.floor() when timestamp is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found