I am trying to take each row of this contrast matrix, perform the operation defined in the denominator variable, add them up, and then divide by the number of rows. When I try to do something like this, I get an "invalid syntax error" (using python 3). This question is from the fMRI univariate analysis context. The X is predefined, you can ignore it. I am just trying to do a dot product with matrices in the denominator variable.
X = simulate_two_predictors(N=350, shift=30, TR=2)
contrast_matrix = np.array([
[0, 1, 0],
[0, 0, 1],
[0, 1, -1]
])
for i in range(contrast_matrix.shape[0]):
denominator = (contrast_matrix[i,:] @ inv(X.T @ X) @
(contrast_matrix[i,:].T))
return contrast_matrix.size / denominator
Can you help me with it? I am quite new.
Since I do not know how the output of X simulate_two_predictors look like, I have made a few assumptions.
Correct me if I'm wrong, the return keyword is only valid given that you are returning from a function.
import numpy as np
contrast_matrix = np.array([[0, 1, 0],
[0, 0, 1],
[0, 1, -1]])
X = simulate_two_predictors(N=350, shift=30, TR=2)
for i in range(contrast_matrix.shape[0]):
# do something here
denominator = (contrast_matrix[i,:]) @ (np.linalg.inv(X.T @ X) @ (contrast_matrix[i,:].T))
# reassign value
contrast_matrix[i,:] = (contrast_matrix.size / denominator)
print(contrast_matrix)