using System; using System.Collections.Generic; using System.Text; using NumSharp.Extensions; namespace NumSharp { /// /// NumPy bridge /// public class NumPy { public NDArray arange(int stop) { return arange(0, stop); } public NDArray 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(); n.ARange(stop, start, step); return n as NDArray; } case "Double": { var n = new NDArray(); n.ARange(stop, start, step); return n as NDArray; } default: throw new NotImplementedException(); } } public NDArray array(T[] data) { var n = new NDArray(); n.Data = data; n.Shape = new Shape(new int[] { data.Length }); return n; } public NDArray 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(); n.Data = all; n.Shape = new Shape(new int[] { data.Length, data[0].Length }); return n; } public NDArray hstack(params NDArray[] nps) { var n = new NDArray(); return n.HStack(nps); } public NDArrayRandom random { get { return new NDArrayRandom(); } } public NDArray reshape(NDArray np, params int[] shape) { np.Shape = new Shape(shape); return np; } public NDArray vstack(params NDArray[] nps) { var n = new NDArray(); return n.VStack(nps); } public NDArray zeros(params int[] shape) { switch (typeof(T).Name) { case "Int32": { var n = new NDArray(); n.Zeros(shape); return n as NDArray; } case "Double": { var n = new NDArray(); n.Zeros(shape); return n as NDArray; } default: throw new NotImplementedException(); } } } }