-2

Basically I have these arrays

print(img_arr[0].shape)->(returns) (122218,)
print(img_arr1[0].shape)->(returns) (125204,)

so when I did

difference = np.subtract(img_arr[0],img_arr1[0])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9596/1605062018.py in <module>
----> 1 difference = np.subtract(img_arr[0],img_arr1[0])
      2 #print(img_arr[0].shape)
      3 #print(img_arr1[0].shape)

ValueError: operands could not be broadcast together with shapes (122218,) (125204,)

So in order to subtract arrays the shape should be the same. Hence, I did this to find the difference so that I can see the distribution of difference

difference = []
for idx, value in enumerate(img_arr[0]):
    difference.append(img_arr[0][idx] - img_arr1[0][idx])

sns.displot(data=difference,kde=True)

So I just need some guidance that is my above approach valid to find the difference? enter image description here

J. Doe
  • 155
  • 1
  • 11
  • You can `slice` the larger array to the size of the smaller one to avoid the for loop. More information is needed to decide if this operation is valid. In general, this approach is not valid. – Michael Szczesny May 06 '22 at 06:41
  • The question needs more focus: This question currently includes multiple questions in one. It should focus on one problem only. – Trenton McKinney May 06 '22 at 14:57
  • This question needs a [SSCCE](http://sscce.org/). Please see [How to ask a good question](https://stackoverflow.com/help/how-to-ask). Always provide a complete [mre] with **code, data, errors, current output, and expected output**, as **[formatted text](https://stackoverflow.com/help/formatting)**. If relevant, only plot images are okay. If you don't include an mre, it is likely the question will be downvoted, closed, and deleted. – Trenton McKinney May 06 '22 at 14:57

1 Answers1

0

What you're currently doing is finding the element-wise difference of each of the 122218 elements in img_arr[0] and the first 122218 of the total 125204 elements in img_arr1[0], and finally plotting a distribution plot of the difference. Your approach is valid, if you are okay with losing the last 2986 (125204 - 122218) elements of img_arr1[0], which are not being used anywhere.

karthik_ghorpade
  • 374
  • 1
  • 10