首页 > 解决方案 > Python - Summation of a function implementation

问题描述

How can I implement the following function in python using numpy:

enter image description here

Where:

The values of X and X` are read from a csv file I have. I tried the following but it is not getting me any result:

import numpy as np
import matplotlib.pyplot as plt
import math

data = np.loadtxt('data.csv',delimiter=',')

x = data[:,:500]
x_hat = data[:,501:1001]

n = 400
w = np.random.uniform(0,1,500)
Kapprox = (1/n)*np.sum( max(0,w*x)*max(0,w*x_hat),n)

plt.plot(Kapprox)

标签: pythonfunctionnumpysum

解决方案


I think that this should work:

Kapprox = (1/n)*np.sum([max(0, np.matmul(wi, x).max())*max(0, np.matmul(wi, x_hat).max()) for wi in your_w])


推荐阅读