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.

TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'

See original GitHub issue

I’m using Gizeh library and I get the above error upon installing the latest version of Numpy. There was no error with Numpy version 1.08.

File "animation/target_animation.py", line 161, in draw
    fill = gizeh.ImagePattern(self.bg.data, self.bg.pos, filter='best')
  File "build/bdist.linux-x86_64/egg/gizeh/gizeh.py", line 295, in __init__
  File "build/bdist.linux-x86_64/egg/gizeh/gizeh.py", line 50, in from_image
TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'

Is there a workaround or would you fix this issue please?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

25reactions
sebergcommented, Jun 2, 2016

Typically this is code such as a += b and you need to make it np.add(a, b, out=a, casting="unsafe") (if you are sure you want the unsafe cast behaviour. Or, unless b is huge and it is safe, maybe just cast b first.

10reactions
mantielerocommented, Mar 25, 2018

In my case, I had a similar issue. It was solved as suggested by seberg. I replaced line 40 in gizeh.py:

arr += image.flatten()

with line:

arr = np.add(arr, image.flatten(), out=arr, casting="unsafe")

I hope this helps somebody else.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm getting a TypeError for a += b, but not b += a (numpy)
Report the whole TypeError! ----> 3 a += b TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('int64') with casting rule ......
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' · Problem:.
Read more >
Cannot cast ufunc 'add' output from dtype('x') to ... - CSDN博客
_exceptions.UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule.
Read more >
can add int to float but can't add float to int | Sololearn
import numpy as np a = np.full((2,3),3, dtype=int) print(a) ... print(a) 14 TypeError: Cannot cast ufunc add output from dtype('float64') to ...
Read more >
numpy.true_divide — NumPy v1.24 Manual
numpy.true_divide(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'divide'>#.
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