Reputation: 405
I'm importing data from a CSV and trying to run an analysis on it, but I need to multiply a matrix by its transpose.
def C_matrices(F11_list, F12_list, F21_list, F22_list):
C11_list = []
C12_list = []
C21_list = []
C22_list = []
for F11 in F11_list:
pos = F11_list.index(F11)
F = np.array([[float(F11), F12_list[pos]], [F21_list[pos], F22_list[pos]]])
print F
Ft = F.transpose()
print Ft
C = np.matmul(F, Ft)
C11_list.append(C[:1, :1])
C12_list.append(C[1:, 2:])
print C[:1, :1]
print C[1:, 2:]
break
And I get:
[['1.0' '0']
Traceback (most recent call last):
['0' '1']]
File "C:/Users/lukec/Desktop/School/3rd Year/1st Quarter/BENG 110/Project/read_F.py", line 48, in <module>
[['1.0' '0']
control()
['0' '1']]
File "C:/Users/lukec/Desktop/School/3rd Year/1st Quarter/BENG 110/Project/read_F.py", line 45, in control
C_matrices(F11_list, F12_list, F21_list, F22_list)
File "C:/Users/lukec/Desktop/School/3rd Year/1st Quarter/BENG 110/Project/read_F.py", line 34, in C_matrices
C = np.matmul(F, Ft)
TypeError: invalid data type for einsum
I'm not sure why einsum is failing, I get a 2x2 matrix times a 2x2 matrix. Any help would be greatly appreciated!
Upvotes: 2
Views: 2128
Reputation: 1637
You can see from the output that the elements of the array are not numbers, but strings
[['1.0' '0']
Make sure to cast the components into numbers float(foo)
before operating
Upvotes: 3