I have a 1D numpy array (y) and 2D numpy array (x) and I calculate correlation between y and every column in x as below:
import numpy as np
from scipy.stats import pearsonr
rng = np.random.default_rng(seed=42)
x = rng.random((3, 3))
y = rng.random(3)
for i in range(x.shape[1]):
print( pearsonr(x[:, i], y)[0] )
I was wondering how I can get the correlation values without For loop. Is there any way?