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.

Compatibility of `DeviceArray` with `PIL.Image.fromarray()` to mirror numpy behavior

See original GitHub issue

This is just a “quality of life” feature request, but twice now I’ve had to import the real numpy to do this sort of thing:

PIL.Image.fromarray(np.array(jnp_array)).show()

It would be nice to be able to avoid importing the real numpy and just write:

PIL.Image.fromarray(jnp_array).show()

Apologies if this is actually trivially achievable without importing the real numpy - I’m new to Python. Seems possible since no one has raised this issue yet. But then again, it’d be nice to have compatibility if it’s possible, since this Image.fromarray(numpy_array).show() pattern seems common?

Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hawkinspcommented, Sep 16, 2021

JAX doesn’t implement __array_interface__, but it does implement the PEP 3118 buffer protocol which is extremely similar. We could support both, most likely.

0reactions
shoyercommented, Sep 16, 2021

I see no reason why PIL should not handle __array__. This would also give them out of the box support for other array-convertible types in Python like those from Xarray and Dask, which seems nice.

On the other hand, I guess JAX could also easily implement __array_interface__, likely by converting into a NumPy array and then calling ndarray. __array_interface__().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange PIL.Image.fromarray behaviour with numpy zeros and ...
I've created 2 matrices size 100 by 100: first only zeroes (np.zeros) and second only ones (np.ones), expecting totally black image with ones, ......
Read more >
jax.numpy package - JAX documentation - Read the Docs
DeviceArray ` objects are designed to work seamlessly with Python standard library ... slightly different behavior than numpy.ndarray.astype() in some cases.
Read more >
Image processing with Python, NumPy - nkmk note
array() returns 3D ndarray whose shape is (row (height), column (width), color (channel)) . from PIL import Image import numpy as np ...
Read more >
pil imagefromarray的推薦與評價, 網紅們這樣回答 - 最新趨勢觀測站
Strange PIL.Image.fromarray behaviour with numpy zeros and ones in mode='1'. There should be some kinda puzzle for me. Accordingly to PIL documentation it...
Read more >
Supported NumPy features - Numba
The following scalar types and features are not supported: Arbitrary Python objects; Half-precision and extended-precision real and complex numbers; Nested ...
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