Compatibility of `DeviceArray` with `PIL.Image.fromarray()` to mirror numpy behavior
See original GitHub issueThis 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:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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 callingndarray. __array_interface__()
.