Enjoying Python-Fiddle? Please upvote our launch on Product Hunt today to help spread the word!
import numpy as np import cv2 shape = (5000, 4000, 3) random_numbers = np.random.uniform(150, 255, shape) rows, cols, chans = random_numbers.shape # Call into numpy using float32 random_numbers_32 = np.reshape(random_numbers, (rows * cols, chans)).astype(np.float32) sum_float32 = random_numbers_32.sum(axis=0) means_float32 = random_numbers_32.mean(axis=0) print(f"Mean of random numbers (float32): {means_float32} | {sum_float32[0]:.6f} {sum_float32[1]:.6f} {sum_float32[2]:.6f}") theo_32_limit = (2**32)/(shape[0]*shape[1]) print(f"Mean using theoretical 2^32 limit: {theo_32_limit}") if(abs(theo_32_limit - means_float32[0]) < 0.0001): print(f"Match? YES") else: print(f"Match? NO!") # Call into numpy using float64 random_numbers_64 = np.reshape(random_numbers, (rows * cols, chans)).astype(np.float64) sum_float64 = random_numbers_64.sum(axis=0) means_float64 = random_numbers_64.mean(axis=0) print(f"Mean of random numbers (float64): {means_float64} | {sum_float64[0]:.6f} {sum_float64[1]:.6f} {sum_float64[2]:.6f}")
line 5, in <module> random_numbers = np.random.uniform(150, 255, shape) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "numpy/random/mtrand.pyx", line 1157, in numpy.random.mtrand.RandomState.uniform File "_common.pyx", line 636, in numpy.random._common.cont numpy.core._exceptions._ArrayMemoryError: Unable to allocate 458. MiB for an array with shape (5000, 4000, 3) and data type float64