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.

Division broken when dtype specified

See original GitHub issue

In a head build using python 3:

>>> np.__version__
'1.8.0.dev-069e9b0'
>>> np.divide(.4, 1.0, dtype=np.float)
0.0
>>> np.divide(.4, 1.0)
0.40000000000000002

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:22 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
Dobatymocommented, Jul 25, 2017

there are still problems with division: https://stackoverflow.com/questions/45278112/numpy-integer-division-sometimes-yields-wrong-results-when-casted

>>> np.true_divide(200, 100, dtype=np.float64)
-0.56000000000000005
>>> np.true_divide(200, 100, dtype=np.float32)
2.0

python 3, numpy 1.13.1

0reactions
njsmithcommented, Jul 27, 2017

Yeah, the lack of a coherent theory about what dtype means bothers me too. Defining it to mean “this is the output type I want” would make some sense, and I think actually work if our type resolution code would try to pick the “best” intermediate type instead of casting int64 to float16, but (a) that’s not how our type resolution code works, and (b) I feel like there are cases where dtype is used to indicate intermediate precision or similar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Given a date range how can we break it up into N ...
I thought I would speed this up by breaking up the date range into non-overlapping intervals and use multiprocessing on each interval. My ......
Read more >
Essential basic functionality — pandas 1.5.2 documentation
pandas offers various functions to try to force conversion of types from the object dtype to other types. In cases where the data...
Read more >
NumPy 1.21.0 Release Notes
dtype attribute must return a dtype. A DeprecationWarning is now given if the . dtype attribute of an object passed into np. dtype...
Read more >
Pandas Tutorial: Data analysis with Python: Part 2
Other (please specify), What type of cranberry saucedo you typically ... Female 544 Male 481 NaN 33 Name: What is your gender?, dtype:...
Read more >
dask.dataframe.read_csv
In some cases it can break up large files: ... If True, all integer columns that aren't specified in dtype are assumed to...
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