Table of Contents

NumSharp

Write NumPy in C#.

NumSharp brings NumPy's API to .NET: the same functions, dtypes, broadcasting and views, tested against NumPy's own output. Its arrays cross into Python, PyTorch, ONNX Runtime and TorchSharp, most of them without a copy.

dotnet add package NumSharp
Start with the basics Quickstart

Same names, same slicing, same output.

example.pyPython with NumPy
Program.csC# with NumSharp
import numpy as npusing NumSharp;
a = np.arange(12).reshape(3, 4)var a = np.arange(12).reshape(3, 4);
v = a[1:, ::2] # a view, no copyvar v = a["1:, ::2"]; // a view, no copy
v[0, 0] = 100 # writes through to av[0, 0] = 100; // writes through to a
print(a.sum(axis=0))Console.WriteLine(a.sum(axis: 0));
> python example.py
[108  15  18  21]
> dotnet run
[108  15  18  21]

Where an NDArray can go

Each box names a library and how an NDArray crosses into it; its color names the NumSharp package that brings it. Hover a box to open the library's own site or its page in these docs. Read the interoperability guide

Documentation

Learn NumSharp

  • The absolute basics

    Arrays, shapes, indexing and math, starting from zero.

  • Quickstart

    The main features on one page, for readers who know NumPy.

  • NDArray

    Creation, shape, indexing, views and copies, operators and storage.

  • Data types

    The 15 numeric dtypes and the text dtypes, with NumPy's names, promotion and casting.

  • Strings and bytes

    Fixed-width bytes and Unicode, variable-width StringDType, numpy.char.

  • API reference

    Every public type and member, under NumPy's names.

How it works

  • Broadcasting

    How operands of different shapes combine without copying.

  • Memory and buffers

    Unmanaged storage, ownership, lifetimes and zero-copy buffers.

  • NDIter

    The iterator that runs strided, buffered and fused loops.

  • IL generation

    SIMD kernels compiled at runtime for each dtype and layout.

  • Interoperability

    One buffer shared with Python, PyTorch, ONNX Runtime, ML.NET and more.

Measured against NumPy

Source on GitHubPackage on NuGet