You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NumSharp is a .NET port of Python's NumPy library. This API reference is organized by functionality, matching NumPy's documentation structure.
Core Types
The essential types for working with NumSharp.
Type
Description
@NumSharp.NDArray
The main n-dimensional array type
@NumSharp.np
Static API class (like import numpy as np in Python)
@NumSharp.Shape
Array dimensions and strides
@NumSharp.Slice
Slice specification for array indexing
@NumSharp.Generic.NDArray`1
Generic typed wrapper for type-safe access
Quick Example
usingNumSharp;// Create arraysvara=np.array(new[]{1,2,3,4,5});varb=np.zeros((3,4));varc=np.arange(10);// Operationsvarsum=np.sum(a);varreshaped=a.reshape(5,1);varsliced=a["1:4"];// Elements 1, 2, 3
Array Creation
Functions for creating new arrays.
Function
Description
np.array(data)
Create array from existing data
np.zeros(shape)
Array filled with zeros
np.zeros_like(a)
Array of zeros with same shape as a
np.ones(shape)
Array filled with ones
np.ones_like(a)
Array of ones with same shape as a
np.empty(shape)
Uninitialized array
np.full(shape, value)
Array filled with a constant value
np.eye(N)
Identity matrix
np.arange(start, stop, step)
Evenly spaced values within interval
np.linspace(start, stop, num)
Evenly spaced values (specify count)
np.meshgrid(x, y)
Coordinate matrices from vectors
np.copy(a)
Return a copy of the array
np.asarray(a)
Convert input to array
np.frombuffer(buffer)
Create array from buffer
Stacking & Joining
Functions for combining multiple arrays.
Function
Description
np.concatenate(arrays, axis)
Join arrays along an existing axis
np.stack(arrays, axis)
Join arrays along a new axis
np.vstack(arrays)
Stack arrays vertically (row-wise)
np.hstack(arrays)
Stack arrays horizontally (column-wise)
np.dstack(arrays)
Stack arrays depth-wise (along 3rd axis)
Math Operations
Arithmetic and mathematical functions.
Arithmetic Operators
Operator
Description
a + b
Element-wise addition
a - b
Element-wise subtraction
a * b
Element-wise multiplication
a / b
Element-wise division
a % b
Element-wise modulo
-a
Element-wise negation
Math Functions
Function
Description
np.sum(a, axis)
Sum of array elements
np.prod(a)
Product of array elements
np.cumsum(a)
Cumulative sum
np.sqrt(a)
Element-wise square root
np.power(a, n)
Element-wise power
np.abs(a)
Element-wise absolute value
np.sign(a)
Element-wise sign
np.floor(a)
Element-wise floor
np.ceil(a)
Element-wise ceiling
np.round(a)
Element-wise rounding
np.clip(a, min, max)
Clip values to range
np.maximum(a, b)
Element-wise maximum
np.minimum(a, b)
Element-wise minimum
Exponentials & Logarithms
Function
Description
np.exp(a)
Element-wise exponential
np.exp2(a)
Element-wise 2^x
np.expm1(a)
exp(x) - 1
np.log(a)
Natural logarithm
np.log2(a)
Base-2 logarithm
np.log10(a)
Base-10 logarithm
np.log1p(a)
log(1 + x)
Trigonometric Functions
Function
Description
np.sin(a)
Element-wise sine
np.cos(a)
Element-wise cosine
np.tan(a)
Element-wise tangent
Statistics
Statistical functions.
Function
Description
np.mean(a, axis)
Arithmetic mean
np.std(a, axis)
Standard deviation
np.var(a, axis)
Variance
np.amax(a, axis)
Maximum value
np.amin(a, axis)
Minimum value
Sorting & Searching
Functions for sorting arrays and finding elements.
Function
Description
np.argsort(a)
Indices that would sort an array
np.argmax(a, axis)
Index of maximum value
np.argmin(a, axis)
Index of minimum value
np.searchsorted(a, v)
Find indices for inserting values
np.nonzero(a)
Indices of non-zero elements
Linear Algebra
Matrix and vector operations.
Function
Description
np.dot(a, b)
Dot product / matrix multiplication
np.matmul(a, b)
Matrix product (@ operator)
np.outer(a, b)
Outer product of two vectors
Shape Manipulation
Functions for changing array shape and dimensions.
Function
Description
np.reshape(a, shape)
Reshape without changing data
a.reshape(shape)
Instance method for reshape
np.transpose(a)
Permute array dimensions
a.T
Transpose property
np.ravel(a)
Flatten to 1-D array (returns view)
a.flatten()
Flatten to 1-D array (returns copy)
np.squeeze(a)
Remove axes of length 1
np.expand_dims(a, axis)
Insert a new axis
np.swapaxes(a, ax1, ax2)
Swap two axes
np.moveaxis(a, src, dst)
Move axes to new positions
np.rollaxis(a, axis)
Roll axis backwards
np.atleast_1d(a)
Convert to at least 1-D
np.atleast_2d(a)
Convert to at least 2-D
np.atleast_3d(a)
Convert to at least 3-D
Indexing & Slicing
NumSharp supports Python-style array indexing and slicing.
Slice Syntax
a[":"]// All elementsa["1:5"]// Elements 1-4 (stop exclusive)a["::2"]// Every 2nd elementa["-1"]// Last element (reduces dimension)a["::-1"]// Reverseda[":, 0"]// All rows, first columna["..., -1"]// Ellipsis fills dimensions