首页 > 解决方案 > 从 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);

但我想我只是不明白第一次转换是如何工作的。

标签: pythonc#unity3d

解决方案


想出了解决办法。它的:

Vector<double>.Build.Dense(bands, i => -1 + (dx / 2) + i++ * dx);

推荐阅读