NumSharp icon indicating copy to clipboard operation
NumSharp copied to clipboard

How to convert NDArray to list

Open Sullivanecidi opened this issue 5 years ago • 8 comments

It is really a big surprise for me to find the Numsharp. Here is little question with using the NumSharp: How to convert the NDArray data to list ? since in VB.net, list is the frequently used. For example: dim x_data, y_data as NDArray dim y() as double x_data = np.linspace(0,100,500) y_data = x_data * 2 + np.random.randn(500)

how to convert y_data to y() ?

Thanks!

Sullivanecidi avatar Mar 18 '20 00:03 Sullivanecidi

x_data.ToArray<double>()

Oceania2018 avatar Mar 18 '20 02:03 Oceania2018

x_data.ToArray<double>()

Do you mean y = y_data.ToArray(of double)() it doesn't work at all......

Sullivanecidi avatar Mar 18 '20 03:03 Sullivanecidi

VB.Net don't support Of unmanaged 目前看到的情况是,VB.Net 不支持 C# 7.3 新的 unmanaged 泛型约束。 如果想要使用,可能需要变通一下了。

Jiuyong avatar Mar 18 '20 05:03 Jiuyong

x_data.ToArray<double>()

Do you mean y = y_data.ToArray(of double)() it doesn't work at all......

I offer a lower level solution:)

Dim x_data, y_data As NDArray x_data = np.linspace(0, 100, 500) y_data = x_data * 2 + np.random.randn(500)

Dim y(y_data.size - 1) As Double For i = 0 To y_data.size - 1 y(i) = y_data(i) Next i

Debugging results: image Please confirm if it can solve your problem。

pepure avatar Mar 18 '20 06:03 pepure

VB.Net don't support Of unmanaged 目前看到的情况是,VB.Net 不支持 C# 7.3 新的 unmanaged 泛型约束。 如果想要使用,可能需要变通一下了。

那就可能是按照楼上这位了,一个一个取出来。谢谢你了~

Sullivanecidi avatar Mar 18 '20 07:03 Sullivanecidi

Thanks very much! this is the alternative way, since VB.net don't support the unmanaged constraint.

Sullivanecidi avatar Mar 18 '20 07:03 Sullivanecidi

VB.Net don't support Of unmanaged 目前看到的情况是,VB.Net 不支持 C# 7.3 新的 unmanaged 泛型约束。 如果想要使用,可能需要变通一下了。

我刚试了下c#,是可以用toArray()实现的。

Sullivanecidi avatar Mar 18 '20 08:03 Sullivanecidi

是的,C#肯定没问题啊。 还有个稍微好一点的解决方案。 就是用C#弄一个缝合项目,然后VB项目引用。

Jiuyong avatar Mar 30 '20 02:03 Jiuyong