Giter VIP home page Giter VIP logo

numsharp's Introduction

NumSharp

NuGet Join the chat at https://gitter.im/publiclab/publiclab AppVeyor codecov Badge

NumSharp (NS) is a NumPy port to C# targetting .NET Standard.
NumSharp is the fundamental package needed for scientific computing with C# and F#.

Is it difficult to translate python machine learning code into .NET? Because too many functions can’t be found in the corresponding code in the .NET SDK. NumSharp is the C# version of NumPy, which is as consistent as possible with the NumPy programming interface, including function names and parameter locations. By introducing the NumSharp tool library, you can easily convert from python code to C# or F# code. Here is a comparison code between NumSharp and NumPy (left is python, right is C#):

comparision

Bold Features

  • Use of Unmanaged Memory and fast unsafe algorithms.
  • Broadcasting n-d shapes against each other. (intro)
  • NDArray Slicing and nested/recusive slicing (nd["-1, ::2"]["1::3, :, 0"])
  • Axis iteration and support in all of our implemented functions.
  • Full and precise (to numpy) automatic type resolving and conversion (upcasting, downcasting and other cases)
  • Non-copy - most cases, similarly to numpy, does not perform copying but returns a view instead.
  • Almost non-effort copy-pasting numpy code from python to C#.
  • Wide support for System.Drawing.Bitmap. (read more)

Implemented APIs

The NumPy class is a high-level abstraction of NDArray that allows NumSharp to be used in the same way as Python's NumPy, minimizing API differences caused by programming language features, allowing .NET developers to maximize Utilize a wide range of NumPy code resources to seamlessly translate python code into .NET code.

Install NumSharp in NuGet

PM> Install-Package NumSharp

How to use

using NumSharp;

var nd = np.full(5, 12); //[5, 5, 5 .. 5]
nd = np.zeros(12); //[0, 0, 0 .. 0]
nd = np.arange(12); //[0, 1, 2 .. 11]

// create a matrix
nd = np.zeros((3, 4)); //[0, 0, 0 .. 0]
nd = np.arange(12).reshape(3, 4);

// access data by index
var data = nd[1, 1];

// create a tensor
nd = np.arange(12);

// reshaping
data = nd.reshape(2, -1); //returning ndarray shaped (2, 6)

Shape shape = (2, 3, 2);
data = nd.reshape(shape); //Tuple implicitly casted to Shape
    //or:
nd =   nd.reshape(2, 3, 2);

// slicing tensor
data = nd[":, 0, :"]; //returning ndarray shaped (2, 1, 2)
data = nd[Slice.All, 0, Slice.All]; //equivalent to the line above.

// nd is currently shaped (2, 3, 2)
// get the 2nd vector in the 1st dimension
data = nd[1]; //returning ndarray shaped (3, 2)

// get the 3rd vector in the (axis 1, axis 2) dimension
data = nd[1, 2]; //returning ndarray shaped (2, )

// get flat representation of nd
data = nd.flat; //or nd.flatten() for a copy

// interate ndarray
foreach (object val in nd)
{
    // val can be either boxed value-type or a NDArray.
}

var iter = nd.AsIterator<int>(); //a different T can be used to automatically perform cast behind the scenes.
while (iter.HasNext())
{
    //read
    int val = iter.MoveNext();

    //write
    iter.MoveNextReference() = 123; //set value to the next val
    //note that setting is not supported when calling AsIterator<T>() where T is not the dtype of the ndarray.
}

How to run benchmark

C: \> dotnet NumSharp.Benchmark.dll nparange

NumSharp is referenced by

You might also be interested in NumSharp's sister project Numpy.NET which provides a more whole implementation of numpy by using pythonnet and behind-the-scenes deployment of python (read more).

NumSharp is a member project of SciSharp.org which is the .NET based ecosystem of open-source software for mathematics, science, and engineering.

Regen Templating

Our library contains over 150,000 lines of repetitive generated code, mostly for handling different data types without hurting performance.
The templates can be recognized with #if _REGEN blocks and are powered by Regen Templating Engine.
Regen is a powerful external tool (Visual studio extension, download here) that generates on demand based on a C#-like regen-lang.

numsharp's People

Contributors

aoaaquarius avatar dania-vera avatar deepakkumar1984 avatar devbox10 avatar dotchris90 avatar dsyme avatar emrahsungu avatar esther2013 avatar fdncred avatar hanabi1224 avatar henon avatar huazhikui avatar jetstreamroysprowl avatar katdti avatar kevinma0207 avatar moloneymb avatar nucs avatar oceania2018 avatar plankton555 avatar pppbr avatar rikki-tavi avatar vunb avatar yamachu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.