I need to calculate the sum of a list of matrices, however, I can't use np.sum, even with axis=0, I don't know why. The current solution is a loop, but is there a better way for that?
import numpy as np
SAMPLE_SIZES = [10, 100, 1000, 10000]
ITERATIONS = 1
MEAN = np.array([1, 1])
COVARIANCE = np.array([[1, 0.5], [0.5, 1]])
for sample_size in SAMPLE_SIZES:
max = -1
for i in range(ITERATIONS):
xs = np.random.multivariate_normal(MEAN, COVARIANCE, size=sample_size)
sigma = [[0, 0], [0, 0]]
for x in xs:
sigma += np.outer((x-MEAN), (x-MEAN)) / (sample_size-1)
In the code above, can I replace the last loop using some numpy function? I guess using a loop would be not efficient if the data is very large.
SAMPLE_SIZESis a Python list, not a Numpy array.xs. Array? List? Shape ,dtype?. IsMEANa scalar?np.sum, and the error message.