Как я могу это вычислить?Python

Программы на Python
Гость
Как я могу это вычислить?

Сообщение Гость »


Предположим, у меня есть следующий массив 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
I want to do this computation for t=0, 1, 2, 3, 4.
  • 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
I.e.

Код: Выделить всё

t = 0
v0 = my_data[t:,]
my_data_dot = np.dot(my_data, v0)
my_data_sum = np.sum(my_data_dot)/(n-t)
How can I do this without using looping statements?
Please show me the simplest way.


Источник: https://stackoverflow.com/questions/781 ... mpute-this

Вернуться в «Python»