python - Python - Summation of a function implementation
问题描述
How can I implement the following function in python using numpy:
Where:
- X is a numpy matrix (500 * 500)
- X` is another numpy matrix (500 * 500)
- Wi is a weight vector of dimensionality equal to the dimensionality of X, with each entry in Wi drawn independently from
- n could be any large value
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)
解决方案
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])
推荐阅读
- markdown - 如何在 pandoc markdown 中调整内联代码的背景颜色框大小
- javascript - 如何更新 Javascript 中另一个模块中存在的对象?
- python - 有谁知道如何匹配两个二维列表?
- c - i2c stm32 nucleo 无法建立连接
- r - 从数据框中计算相应的第 n 个百分位数
- php - 使用 php 将 API 发布请求发送到 azure 部署的模型
- api - 何时在 Live 服务器上启用 Protocol v4.0?
- sql - 在 SQL Server 的列分配中包含超链接的更新语句
- sql-server - 将动态查询导出到表
- sparql - 如何使用 SPARQL 获取数据属性断言值?