Repository navigation
Expand file tree
/
Copy pathNumPyGeneric.cs
More file actions
106 lines (89 loc) · 2.73 KB
/
Copy pathNumPyGeneric.cs
File metadata and controls
106 lines (89 loc) · 2.73 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
using System;
using System.Collections.Generic;
using System.Text;
using NumSharp.Core.Extensions;
namespace NumSharp.Core
{
/// <summary>
/// API bridge between NumSharp and Python NumPy
/// </summary>
[Obsolete("please use NumPy")]
public class NumPyGeneric<T>
{
public NDArrayGeneric<T> arange(int stop)
{
return arange(0, stop);
}
public NDArrayGeneric<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 NDArrayGeneric<int>();
n.arange(stop, start, step);
return n as NDArrayGeneric<T>;
}
case "Double":
{
var n = new NDArrayGeneric<double>();
n.arange(stop, start, step);
return n as NDArrayGeneric<T>;
}
default:
throw new NotImplementedException();
}
}
public NDArrayGeneric<T> array(T[] data)
{
var n = new NDArrayGeneric<T>();
n.Data = data;
n.Shape = new Shape(new int[] { data.Length });
return n;
}
public NDArrayGeneric<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 NDArrayGeneric<T>();
n.Data = all;
n.Shape = new Shape(new int[] { data.Length, data[0].Length });
return n;
}
public NDArrayGeneric<double> hstack(params NDArrayGeneric<double>[] nps)
{
var n = new NDArrayGeneric<double>();
return n.HStack(nps);
}
public NumPyRandom random
{
get
{
return new NumPyRandom();
}
}
public NDArrayGeneric<int> reshape(NDArrayGeneric<int> np, params int[] shape)
{
np.Shape = new Shape(shape);
return np;
}
public NDArrayGeneric<double> vstack(params NDArrayGeneric<double>[] nps)
{
var n = new NDArrayGeneric<double>();
return n.VStack(nps);
}
}
}