Reputation: 319
I'm using python 2.7 And trying to get this code to work and keep receiving an error
nsample = 50
sig = 0.25
x1 = np.linspace(0,20, nsample)
X = np.c_[x1, np.sin(x1), (x1-5)**2, np.ones(nsample)]
beta = masterAverageList
y_true = np.dot(X, beta)
y = y_true + sig * np.random.normal(size=nsample)
However I keep getting objects are not aligned error I think it has something to do with master average list being a list?
I forgot to mention the master array list has 196 items in it if it matters. They are all floats
How can I correct this?
Thanks for any sugguestions
Upvotes: 0
Views: 6403
Reputation: 16189
You should read up on numpy broadcasting here and here. You are trying to take the dot product between two arrays which have incompatible shapes.
>>> import numpy as np
>>> x1 = np.linspace(0,20,50)
>>> X = np.c_[x1,np.sin(x1),(x1-5)**2,np.ones(50)]
>>> beta = np.ones(196)
>>> y_true = np.dot(X,beta)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: matrices are not aligned
>>> X.shape
(50, 4)
>>> beta.shape
(196,)
I'm not sure what to recommend, since I don't know what you were expecting by taking the dot product between these arrays.
Upvotes: 2