How do I convert the following array into a jpg? (Please help)

I am trying to convert the following NumPy array into an image again(I need to see the image to continue with my project):

I tried the plt image show but it gave me an error that the float variables are not convertible

Instead of including a pickled file, can you please share your current code in a way that allows people to view it online - such as a replit.com repl, GitHub gist, or similar?

It would also help if you could be more specific with your request for help. Where is the error occurring? What research have you done into it so far? What did you try before you got stuck?

2 Likes

JusttoShare/codeforviewingtheimg at main · valimikayilov/JusttoShare (github.com)

More information is needed.

I tried the code above and the error that I got is the following:

C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\cbook\__init__.py:682: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  x = np.array(x, subok=True, copy=copy)
Traceback (most recent call last):
  File "C:\Users\Desktop\Programming in Python 2\ex4\unittest\Imageshow.py", line 9, in <module>
    plt.imshow(im["inputs"][0])
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\pyplot.py", line 2724, in imshow
    __ret = gca().imshow(
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\__init__.py", line 1447, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axes\_axes.py", line 5523, in imshow
    im.set_data(X)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\image.py", line 702, in set_data
    raise TypeError("Image data of dtype {} cannot be converted to "
TypeError: Image data of dtype object cannot be converted to float

I did extensive research but I don’t know how to do it

this how I think that image was converted but I don’t know how to convert it back:

for img in self.found_files:
    loaded = Image.open(img)
    numpyimage = np.asarray(loaded)

I’m no expert on pickle, but shouldn’t you be able to get the data-type of the content? See what data it is made up off? Then look for operations defined on that data? Or ask whoever made this thing how they made it and how to reverse it?

I feel like you are giving us pretty much nothing to work with.

1 Like

https://numpy.org/doc/stable/reference/generated/numpy.asarray.html

Parameters

a: array_like

  Input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.

If your loaded isn’t an array-like type, then you won’t be able to use asarray like this. It appears that your self.found_files could be converted to an array. Is that what you needed to do?

1 Like

that code is what should have been used to convert images into arrays, but now I want to see them as images again. The images are greyscaled, and I need to see them with the help of plt.imshow

plot.shavefig("plot.png)
plot.show()
espero te sirva busca un poco en data scinecie

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.