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.

ufunc cannot be cast with rule `same_kind`

See original GitHub issue

Updgrading to 1.10, I noticed the following new behavior:

In [1]: import numpy as np

In [2]: a = np.array([1,2,3])

In [3]: b = 2.0

In [4]: a /= b
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-b9f4626d3ca8> in <module>()
----> 1 a /= b

TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'l') according to the casting rule ''same_kind''

In [5]: a = a/b

In [6]: a
Out[6]: array([ 0.5,  1. ,  1.5])

See also https://github.com/nipy/dipy/issues/730. Is this an intended new behavior? If so, what does it portend (what should I stop doing?)?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:17
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

17reactions
charriscommented, Oct 12, 2015

Probably means you didn’t see the deprecation warnings since forever 😉 If you want to cast the float result to integer, you can call true_divide with out=a and casting='unsafe' arguments.

0reactions
sirynecommented, May 7, 2019

I got this error while executing this line : X = preprocess_input(X, mode=‘tf’)

I fixed this error by changing tools versions : Numpy – 1.16.1 Pandas – 0.23.0 Matplotlib – 2.2.2 Keras – 2.2.4

hope this would help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot cast ufunc add output from dtype('float64') to ... - GitHub
I'm using Gizeh library and I get the above error upon installing the latest version of Numpy. There was no error with Numpy...
Read more >
UFuncTypeError: Cannot cast ufunc 'det' input from dtype('O ...
UFuncTypeError : Cannot cast ufunc 'det' input from dtype('O') to dtype('float64') with casting rule 'same_kind'? How to avoid this issue?
Read more >
How to fix numpy TypeError: Cannot cast ufunc subtract output ...
How to fix numpy TypeError: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
Read more >
NEP 43 — Enhancing the extensibility of UFuncs - NumPy
It makes a new distinction between the ufunc which can operate on many ... includes the “same-kind” cast and is thus not considered...
Read more >
Array API — NumPy v1.9 Manual
Force a cast to the output type even if it cannot be done safely. ... The rule is that scalars of the same...
Read more >

github_iconTop Related Medium Post

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