Предположим, у меня есть следующий массив numpy:
Код: Выделить всё
import numpy as np
my_data = np.array(
[[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5]])
# obtain the length
n = len(my_data) # 5
- take the t-th row
- compute dot product of the t-th row and the entire array
- compute sum
- divide by (n-t)
- retun all the results as an array
Код: Выделить всё
t = 0
v0 = my_data[t:,]
my_data_dot = np.dot(my_data, v0)
my_data_sum = np.sum(my_data_dot)/(n-t)
Please show me the simplest way.
Источник: https://stackoverflow.com/questions/781 ... mpute-this