0

I have an images data set which I have converted into NumPy array and getting total counts of pixels in individual images. I am using below code for this purpose:

data_custom_script = images data_custom_script = np.array(data_custom_script) import pandas as pd for images in data_custom_script: colours, counts = np.unique(images.reshape(-1,3), axis=0, return_counts=1) #giving these conditions because array has different shapes if counts.shape[0] == 7: counts = np.reshape(counts,(1,7)) if counts.shape[0] == 6: counts = np.reshape(counts,(1,6)) if counts.shape[0] == 5: counts = np.reshape(counts,(1,5)) if counts.shape[0] == 4: counts = np.reshape(counts,(1,4)) if counts.shape[0] == 3: counts = np.reshape(counts,(1,3)) 

Now when I run this code i get result into multiple 1D array for each images like this: enter image description here

Now when I convert this into data frame I got results in the form of individual data frames rather than one

df = pd.DataFrame(counts) print(df) 

enter image description here

I want to get results in the form of a single data frame like this enter image description here

3
  • Reshape to (1,7) makes a 2d array, displayed as [[1 2 3]]. If you really want that you don't need all the if, just do counts = counts[None,:] or counts=counts.reshape(1,-1). Also, you don't show how you collect the counts in the iteration.
    – hpaulj
    CommentedMay 30, 2022 at 15:40
  • Thanks for the suggestion. And can you please guide me how can i convert into single data frame rather than multiple data frames for each imagesCommentedMay 30, 2022 at 15:48
  • counts = np.unique(images.reshape(-1,3), axis=0, return_counts=1). This part of code is collecting counts for imagesCommentedMay 30, 2022 at 16:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.