Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

How can I compute this?

$
0
0

Suppose I have the following numpy array:

import numpy as npmy_data = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]])# obtain the lengthn = len(my_data) # 5

I want to do this computation for t=0, 1, 2, 3, 4.

  1. take the t-th row
  2. compute dot product of the t-th row and the entire array
  3. compute sum
  4. divide by (n-t)
  5. retun all the results as an array

I.e.

t = 0v0 = 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.


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>