Skip to content

NumSharp in .NET Languages

Darren Schroeder edited this page Dec 5, 2018 · 2 revisions

Syntax in C# :

// from more abstract NumPy object
var np = new NumPy<int>();
var list = new int[] { 1, 2, 3 };
var n = np.array(list);

// from 2 to 3 in 5 steps with direct NDArray constructor
var np1 = new NDArray<double>().linspace(2.0, 3.0,5);

// using Matrix inversion and multiplication 
NDArray<double> np1 = new NDArray<double>().arange(4).reshape(2,2);
NDArray<double> np1Inv = np1.inv();
var OncesMatrix = np1.dot(np1Inv);

// convolve
var series1 = new NDArray<double>().array(new double[]{1, 2, 3});
var series2 = new NDArray<double>().array(new double[]{0, 1, 0.5});
            
var series3 = series1.Convolve(series2);

Syntax in Ironpython

# first need to add the NumSharp.Python.dll (at moment need to compile by yourself with dotnet build)
import clr.AddReferenceToFileAndPath('./NumSharp.Python.dll')

# the wrapper class is called numpy ;)
import numpy as np

# standard
a = np.arange(15).reshape(3, 5)
a.ToString()

# from Ironpython list
a = np.array([2,3,4])

# select dtype
c = np.array( [1,2,3,4], np.complex ).reshape(2,2)

#inv 
matrixA = np.array([1,2,3,4]).reshape(2,2)
matrixA_inv = matrixA.inv()
onces = matrixA.dot(matrixA_inv) 
Clone this wiki locally