forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNdArray.AsMatrix.cs
More file actions
32 lines (27 loc) · 847 Bytes
/
NdArray.AsMatrix.cs
File metadata and controls
32 lines (27 loc) · 847 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
31
32
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace NumSharp.Core.Extensions
{
public static partial class NDArrayExtensions
{
public static Matrix<double> AsMatrix(this NDArray<double> np)
{
Matrix<double> npAsMatrix = new Matrix<double>();
int dim0 = np.Shape.Shapes[0];
int dim1 = np.Shape.Shapes[1];
npAsMatrix.Shape = new Shape(new int[] { dim0, dim1 });
npAsMatrix.Data = new double[dim0 * dim1];
for (int idx = 0; idx < dim0;idx++)
{
for (int jdx = 0;jdx < dim1;jdx++)
{
npAsMatrix[idx,jdx] = np[idx,jdx];
}
}
return npAsMatrix;
}
}
}