Fundamentals and usage
These pages clarify the concepts, design decisions, and behavioral rules behind NumSharp - the .NET port of NumPy that targets 1-to-1 API and behavioral compatibility with NumPy 2.x. They are the NumSharp counterparts of NumPy's own NumPy fundamentals guide: one article per NumPy article, rewritten for C# and honest about where a .NET runtime forces NumSharp to diverge.
If you have written NumPy before, these pages are the fastest way to map that knowledge onto NDArray. If you have not, they are the place to build a mental model before reaching for the API reference.
The articles
| Article | What it covers | NumPy original |
|---|---|---|
| Array creation | The six ways to make an NDArray - from .NET sequences, intrinsic functions, joins, disk, raw bytes, and random |
basics.creation |
| Indexing on NDArray | Basic indexing (views), advanced indexing (copies), boolean masks, the flat iterator, and assignment | basics.indexing |
| I/O with NumSharp | The byte-exact .npy/.npz stack, text I/O (loadtxt/savetxt), and raw-binary I/O |
basics.io |
| Data types | The 15 supported dtypes, how they map to NumPy, dtype strings, promotion, and the two types with no NumPy analog | basics.types |
| Broadcasting | How arrays of different shapes combine in arithmetic - the shape rules and the stride-0 mechanism | basics.broadcasting |
| Copies and views | Which operations share memory and which duplicate it, and how to tell | basics.copies |
| Arrays of strings and bytes | The Char dtype, why NumPy's string/bytes dtypes are not ported, and what to use instead |
basics.strings |
| Structured arrays | Why NumSharp does not implement record/structured dtypes, and the .NET-idiomatic alternatives | basics.rec |
| Universal functions (ufunc) basics | Elementwise ops, out=/where=/dtype=, broadcasting, casting, and reductions |
basics.ufuncs |
Data types and Broadcasting already have dedicated, in-depth NumSharp guides (Dtypes, Broadcasting); they are the NumSharp conversions of NumPy's data-types and broadcasting articles, so they are linked here rather than duplicated.
What "convert each NumPy article to a NumSharp one" means
NumSharp's goal is that ported NumPy code behaves identically. So each article follows its NumPy source closely - same concepts, same section order, the same worked examples - but:
- Code is C#, not Python.
np.zeros((2, 3)),arr["1:3, :2"],arr.astype(np.float64). Python slice literals (a[1:5:2]) become strings in C# (a["1:5:2"]) because C# has no slice syntax - see Indexing. - The 15 NumSharp dtypes stand in for NumPy's set. NumSharp adds
DecimalandChar(no NumPy analog) and omitscomplex64, the string/bytes/void/object dtypes,datetime64/timedelta64, and structured dtypes. Each article says plainly where a NumPy feature has no NumSharp counterpart and what to use instead. - Divergences are documented, never silent. Where NumSharp cannot match NumPy exactly (e.g. a C#
int[]is a strong array that wraps on downcast, where a Python list is weak and raises), the article flags it. Behavioral differences are gated in the test suite under theMisalignedcategory.
Where these fit among the other guides
The fundamentals articles are conceptual. When you want the exhaustive how-to, the neighbouring guides go deeper:
- NDArray - the anatomy of the array (storage, shape, strides, the view/copy rule).
- Getting & Setting Values - every accessor for reading and writing, with the conversion and write-through rules.
- Iterating & Enumerating -
flat,nditer, typed/unboxed iteration,.NETinterop. - NumPy Compliance & Compatibility - type promotion (NEP 50) and the broader 2.x parity story.
- Array API Standard - the array-API surface NumSharp implements.
Related reading
- NumPy fundamentals - the upstream guide these pages track.
- NumPy API Coverage & Support - which
np.*functions are implemented.