I am trying to construct a matrix with numpy using an array of random numbers called noise with 4 values which should be multiplied with 8 different numbers from an array called "factor" resulting in 8 rows in the final matrix.
So the matrix should have 4 columns for each value in "noise" and 8 rows for each factor. I don't know how to achieve that.
This is the code I got so for:
import numpy as np
from numpy import random
n = 4
noise = np.random.normal(size=n)
matrix = np.zeros((8,n)) # Pre-allocate matrix
for i in range(1,8):
matrix[:,i] = [[noise]*i]
print(matrix)
I get the error message:
ValueError: setting an array element with a sequence.
matrixis (8,n) andmatrix[:,i]is (n,) shape.noiseis (n,) shape. But what is the shape of[[noise]*i]. It's actually a list, but when turned into an array, what is it?