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.

.ptp() can return negative numbers

See original GitHub issue

This is worked around in https://github.com/numpy/numpy/pull/14381 and mentioned in https://github.com/numpy/numpy/issues/3292#issuecomment-543626173 but still seems to behave like this. I don’t see why anyone would ever want it to return a negative number, so I think it should be considered a bug.

Reproducing code example:

import numpy as np
np.array([32767, -1], np.int16).ptp()

It returns np.int16(-32768), but it should logically return np.uint16(32768) or int(32768).

Numpy/Python version information:

1.17.4 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
WarrenWeckessercommented, May 14, 2020

At a minimum, I guess we should add a warning to the docstring

See https://github.com/numpy/numpy/pull/16240

0reactions
rgommerscommented, May 15, 2020

If there is more interest now in getting peaktopeak–or something like it–into numpy, I can start working on that.

I’d rather not see that, too trivial/niche for numpy at this point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.ptp — NumPy v1.24 Manual
ptp preserves the data type of the array. ... This example shows that a negative value can be returned when the input is...
Read more >
Python 3.6.1 - Numpy.power returns negative values for cube ...
1 Answer 1 ... This happens because the cube of 1963 is greater than the maximum number (2,147,483,647) which can be stored in...
Read more >
NumPy ptp() function - Studytonight
This function is used to return a range of values along an axis. The range can be calculated using range= maximum_value - minimum_value....
Read more >
[SciPy-user] negative values in diagonal of covariance matrix
Hi all, I'm a moderately new user of scipy, trying to make some curve-fitting with it. I wanted to use cov matrix output...
Read more >
Precision Time Protocol Software Configuration Guide for IE ...
Adding PTP to a network can compensate for these latency and delay ... Port 2 returns and generates timestamp t3 for a Pdelay_Resp...
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