0

I have a 50 x 300 pandas data frame titled embeddings and would like to view it as a numpy array. I am using the function view_samples below:

def view_samples(samples, m, n): 
    fig, axes = plt.subplots(figsize=(10, 10), nrows=m, ncols=n, sharey=True, sharex=True) 
    for ax, img in zip(axes.flatten(), samples): 
        ax.xaxis.set_visible(False) 
        ax.yaxis.set_visible(False) 
        im = ax.imshow(1-img.reshape((50,300)), cmap='Greys_r') 
    return fig, axes

And running it as follows:

faces = [embeddings.to_numpy()]
_ = view_samples(faces, 1, 4)

The current result is shown below. Only the first one (leftmost) is correct, the other pictures are not.

current error output

Given the error, I am also trying to rewrite the function such that I do not include subplots, i.e. just the leftmost one.

1 Answer 1

1

The problem is here:

faces = [embeddings.to_numpy()]

That is len(faces)==1. So with:

for ax, img in zip(axes.flatten(), samples): 

you only get to draw once. Maybe you mean:

faces = embeddings.to_numpy()
Sign up to request clarification or add additional context in comments.

3 Comments

I actually get len(faces)==50, and when I use faces = embeddings.to_numpy() : cannot reshape array of size 300 into shape (50,300) so I changed it to (10,30) and it worked!
If you only have one face, why would you expect 4 plots?
I rewrote it to expect one plot. I was trying to achieve that in the end goal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.