-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNUmSharpExtensions.cs
More file actions
30 lines (27 loc) · 880 Bytes
/
NUmSharpExtensions.cs
File metadata and controls
30 lines (27 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using NumSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public static class NumSharpExtensions
{
public static float[] ToFloatArray(this NDArray npArray)
{
double[] doubleArray = npArray.ToArray<double>();
return Array.ConvertAll(doubleArray, item => (float)item);
}
public static float[,] ToFloat2DArray(this NDArray ndArray)
{
var multidimArray = ndArray.ToMuliDimArray<float>();
var floatArray = new float[multidimArray.GetLength(0), multidimArray.GetLength(1)];
for (int i = 0; i < multidimArray.GetLength(0); i++)
{
for (int j = 0; j < multidimArray.GetLength(1); j++)
{
floatArray[i, j] = (float)multidimArray.GetValue(i, j);
}
}
return floatArray;
}
}