forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumPy.cs
More file actions
125 lines (108 loc) · 3.15 KB
/
NumPy.cs
File metadata and controls
125 lines (108 loc) · 3.15 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.Text;
using NumSharp.Extensions;
namespace NumSharp
{
/// <summary>
/// NumPy bridge
/// </summary>
public class NumPy<T>
{
public NDArray<T> arange(int stop)
{
return arange(0, stop);
}
public NDArray<T> arange(int start, int stop, int step = 1)
{
if(start > stop)
{
throw new Exception("parameters invalid");
}
switch (typeof(T).Name)
{
case "Int32":
{
var n = new NDArray<int>();
n.ARange(stop, start, step);
return n as NDArray<T>;
}
case "Double":
{
var n = new NDArray<double>();
n.ARange(stop, start, step);
return n as NDArray<T>;
}
default:
throw new NotImplementedException();
}
}
public NDArray<T> array(T[] data)
{
var n = new NDArray<T>();
n.Data = data;
n.Shape = new Shape(new int[] { data.Length });
return n;
}
public NDArray<T> array(T[][] data)
{
int size = data.Length * data[0].Length;
var all = new T[size];
int idx = 0;
for (int row = 0; row < data.Length; row++)
{
for (int col = 0; col < data[row].Length; col++)
{
all[idx] = data[row][col];
idx++;
}
}
var n = new NDArray<T>();
n.Data = all;
n.Shape = new Shape(new int[] { data.Length, data[0].Length });
return n;
}
public NDArray<double> hstack(params NDArray<double>[] nps)
{
var n = new NDArray<double>();
return n.HStack(nps);
}
public NDArrayRandom random
{
get
{
return new NDArrayRandom();
}
}
public NDArray<int> reshape(NDArray<int> np, params int[] shape)
{
np.Shape = new Shape(shape);
return np;
}
public NDArray<double> vstack(params NDArray<double>[] nps)
{
var n = new NDArray<double>();
return n.VStack(nps);
}
public NDArray<T> zeros(params int[] shape)
{
switch (typeof(T).Name)
{
case "Int32":
{
var n = new NDArray<int>();
n.Zeros(shape);
return n as NDArray<T>;
}
case "Double":
{
var n = new NDArray<double>();
n.Zeros(shape);
return n as NDArray<T>;
}
default:
throw new NotImplementedException();
}
}
}
}