Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62a548d

Browse files
pelsonmgiuca-google
authored andcommitted
compare: Simplify and speed up sum of squares algorithm.
1 parent 4e12012 commit 62a548d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def calculate_rms(expectedImage, actualImage):
263263
else:
264264
histogram = np.histogram(absDiffImage, bins=np.arange(257))[0]
265265

266-
sumOfSquares = sum(count*(i**2) for i, count in enumerate(histogram))
266+
sumOfSquares = np.sum(histogram * np.arange(len(histogram))**2)
267267
rms = np.sqrt(float(sumOfSquares) / num_values)
268268

269269
return rms

0 commit comments

Comments
 (0)