python - 从 python 到 C# 实现 linspace 以获取向量
问题描述
我正在将现有的 Python 脚本翻译成 C# 以在 Unity 项目中使用。我以前有一些实现 arange 的代码(波段和 dx 是数字):
Python: x = np.arange(dx/2,1,dx)
翻译为——
C#: static readonly Vector<double> x = Vector<double>.Build.Dense(bands, i => dx / 2 + i++ * dx);
但是我已经改变了我希望 x 的值在 Python 代码中的值。我在 Python 中将其更改为:
Python: x = np.linspace(-1+dx/2,1-dx/2,n)
但我正在努力弄清楚如何在 C# 中实现这个新函数(linspace)。任何帮助,将不胜感激。我想它是这样的:
static readonly Vector<double> x = Vector<double>.Build.Dense(bands, i => -1 + dx / 2 + i++ * 1 - dx / 2);
但我想我只是不明白第一次转换是如何工作的。
解决方案
想出了解决办法。它的:
Vector<double>.Build.Dense(bands, i => -1 + (dx / 2) + i++ * dx);
推荐阅读
- python - Python http.client - request 和 putrequest 有什么区别?
- sql - 如何根据另一列的分位数将新列插入具有标签 '1'/'2'/'3'/'4' # 的数据库中?
- neo4j - 如何在 Neo4j 中解析 json 并使用 foreach 创建节点?
- php - 获取数据库中的数据并合并重复数据
- c++ - 这样做的正确方法是什么?调用指针到指针到指针中的函数?
- kubernetes - 没有为版本“cronjobber.hidde.co/v1alpha1”注册任何类型的“TZCronJob”
- jestjs - 在不同的测试之间模拟相同的值
- node.js - 在我的nestjs模块中导入另一个模块的存储库
- azure-devops - 如何授予我的 ADO 项目的管理员权限?
- javascript - fullcalendar 根据屏幕宽度动态更改默认视图