Class NDArray
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
Container protocol implementation for NDArray. Provides Python-compatible container protocol methods: contains, hash, len, iter, getitem, setitem
[SuppressMessage("ReSharper", "ParameterHidesMember")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public class NDArray : IIndex, ICloneable, IEnumerable
- Inheritance
-
NDArray
- Implements
- Derived
-
NDArray<TDType>
- Inherited Members
- Extension Methods
Remarks
Constructors
NDArray(IArraySlice, Shape, char)
Constructor which takes .NET array dtype and shape is determined from array
public NDArray(IArraySlice values, Shape shape = default, char order = 'C')
Parameters
valuesIArraySliceshapeShapeorderchar
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(UnmanagedStorage)
Creates a new NDArray with this storage.
public NDArray(UnmanagedStorage storage)
Parameters
storageUnmanagedStorage
NDArray(UnmanagedStorage, Shape)
Creates a new NDArray with this storage.
protected NDArray(UnmanagedStorage storage, Shape shape)
Parameters
storageUnmanagedStorageshapeShapeThe shape to set for this NDArray, does not perform checks.
Remarks
Doesn't copy. Does not perform checks for shape.
NDArray(UnmanagedStorage, ref Shape)
Creates a new NDArray with this storage.
protected NDArray(UnmanagedStorage storage, ref Shape shape)
Parameters
storageUnmanagedStorageshapeShapeThe shape to set for this NDArray, does not perform checks.
Remarks
Doesn't copy. Does not perform checks for shape.
NDArray(NPTypeCode)
Constructor for init data type internal storage is 1D with 1 element
public NDArray(NPTypeCode typeCode)
Parameters
typeCodeNPTypeCodeData type of elements
Remarks
This constructor does not call allocation/>
NDArray(NPTypeCode, Shape)
Constructor which initialize elements with 0 type and shape are given.
public NDArray(NPTypeCode dtype, Shape shape)
Parameters
dtypeNPTypeCodeinternal data type
shapeShapeShape of NDArray
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(NPTypeCode, Shape, bool)
Constructor which initialize elements with 0 type and shape are given.
public NDArray(NPTypeCode dtype, Shape shape, bool fillZeros)
Parameters
dtypeNPTypeCodeinternal data type
shapeShapeShape of NDArray
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(NPTypeCode, TensorEngine)
Constructor for init data type internal storage is 1D with 1 element
protected NDArray(NPTypeCode typeCode, TensorEngine engine)
Parameters
typeCodeNPTypeCodeData type of elements
engineTensorEngineThe engine of this NDArray
Remarks
This constructor does not call allocation/>
NDArray(NPTypeCode, int)
Constructor which initialize elements with length of size
public NDArray(NPTypeCode dtype, int size)
Parameters
dtypeNPTypeCodeInternal data type
sizeintThe size as a single dimension shape
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(NPTypeCode, int, bool)
Constructor which initialize elements with length of size
public NDArray(NPTypeCode dtype, int size, bool fillZeros)
Parameters
dtypeNPTypeCodeInternal data type
sizeintThe size as a single dimension shape
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(NPTypeCode, long)
Constructor which initialize elements with length of size
public NDArray(NPTypeCode dtype, long size)
Parameters
dtypeNPTypeCodeInternal data type
sizelongThe size as a single dimension shape (long for large arrays)
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(NPTypeCode, long, bool)
Constructor which initialize elements with length of size
public NDArray(NPTypeCode dtype, long size, bool fillZeros)
Parameters
dtypeNPTypeCodeInternal data type
sizelongThe size as a single dimension shape (long for large arrays)
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Array, Shape, char)
Constructor which takes .NET array dtype and shape is determined from array
public NDArray(Array values, Shape shape = default, char order = 'C')
Parameters
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type)
Constructor for init data type internal storage is 1D with 1 element
public NDArray(Type dtype)
Parameters
dtypeTypeData type of elements
Remarks
This constructor does not call allocation/>
NDArray(Type, Shape)
Constructor which initialize elements with 0 type and shape are given.
public NDArray(Type dtype, Shape shape)
Parameters
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, Shape, bool)
Constructor which initialize elements with 0 type and shape are given.
public NDArray(Type dtype, Shape shape, bool fillZeros)
Parameters
dtypeTypeinternal data type
shapeShapeShape of NDArray
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, Shape, char)
Constructor which initialize elements with 0 type, shape, and order are given.
public NDArray(Type dtype, Shape shape, char order)
Parameters
dtypeTypeinternal data type
shapeShapeShape of NDArray
ordercharMemory order. Note: Only C-order is supported, F-order parameter is accepted but ignored.
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, TensorEngine)
Constructor for init data type internal storage is 1D with 1 element
protected NDArray(Type dtype, TensorEngine engine)
Parameters
dtypeTypeData type of elements
engineTensorEngineThe engine of this NDArray
Remarks
This constructor does not call allocation/>
NDArray(Type, int)
Constructor which initialize elements with length of size
public NDArray(Type dtype, int size)
Parameters
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, int, bool)
Constructor which initialize elements with length of size
public NDArray(Type dtype, int size, bool fillZeros)
Parameters
dtypeTypeInternal data type
sizeintThe size as a single dimension shape
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, long)
Constructor which initialize elements with length of size (long for >2GB arrays)
public NDArray(Type dtype, long size)
Parameters
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
NDArray(Type, long, bool)
Constructor which initialize elements with length of size (long for >2GB arrays)
public NDArray(Type dtype, long size, bool fillZeros)
Parameters
dtypeTypeInternal data type
sizelongThe size as a single dimension shape
fillZerosboolShould set the values of the new allocation to default(dtype)? otherwise - old memory noise
Remarks
This constructor calls IStorage.Allocate(NumSharp.Shape,System.Type)
Fields
Storage
The internal storage that stores data for this NDArray.
protected UnmanagedStorage Storage
Field Value
tensorEngine
protected TensorEngine tensorEngine
Field Value
Properties
Address
Gets the address that this NDArray starts from.
protected void* Address { get; }
Property Value
- void*
Array
Get: Gets internal storage array by calling IStorage.GetData
Set: Replace internal storage by calling IStorage.ReplaceData(System.Array)
protected IArraySlice Array { get; }
Property Value
Remarks
Setting does not replace internal storage array.
this[NDArray<bool>]
Used to perform selection based on a boolean mask.
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
public NDArray this[NDArray<bool> mask] { get; set; }
Parameters
Property Value
Remarks
Exceptions
- IndexOutOfRangeException
When one of the indices exceeds limits.
- ArgumentException
indices must be of Int type (byte, u/short, u/int, u/long).
this[NDArray<int>[]]
Used to perform selection based on a selection indices.
public NDArray this[params NDArray<int>[] selection] { get; set; }
Parameters
Property Value
Remarks
Exceptions
- IndexOutOfRangeException
When one of the indices exceeds limits.
- ArgumentException
indices must be of Int type (byte, u/short, u/int, u/long).
this[Slice[]]
Slice the array with Python slice notation like this: ":, 2:7:1, ..., np.newaxis"
public NDArray this[params Slice[] slice] { get; set; }
Parameters
sliceSlice[]A string containing slice notations for every dimension, delimited by comma
Property Value
- NDArray
A sliced view
this[long*, int]
Used to perform selection based on given indices.
public NDArray this[long* dims, int ndims] { get; set; }
Parameters
Property Value
this[object[]]
Perform slicing, index extraction, masking and indexing all at the same time with mixed index objects
public NDArray this[params object[] indicesObjects] { get; set; }
Parameters
indicesObjectsobject[]
Property Value
this[string]
Slice the array with Python slice notation like this: ":, 2:7:1, ..., np.newaxis"
public NDArray this[string slice] { get; set; }
Parameters
slicestringA string containing slice notations for every dimension, delimited by comma
Property Value
- NDArray
A sliced view
Shape
The shape representing this NDArray.
public Shape Shape { get; set; }
Property Value
T
The transposed array.
Same as self.transpose().
public NDArray T { get; }
Property Value
Remarks
TensorEngine
The tensor engine that handles this NDArray.
public TensorEngine TensorEngine { get; set; }
Property Value
Unsafe
Provides an interface for unsafe methods in NDArray.
public NDArray._Unsafe Unsafe { get; }
Property Value
base
Gets the array owning the memory, or null if this array owns its data.
public NDArray? @base { get; }
Property Value
- NDArray
An NDArray wrapping the base storage for views, or
nullfor arrays that own their data (e.g., created vianp.arange,np.zeros, orcopy()).
Remarks
NumPy Compatibility: This property mirrors NumPy's ndarray.base attribute.
All views chain to the ultimate owner (not intermediate views).
Example:
var a = np.arange(10); // a.@base == null (owns data)
var b = a["2:5"]; // b.@base.Storage == a.Storage (view)
var c = b["1:2"]; // c.@base.Storage == a.Storage (chains to original!)
var d = a.copy(); // d.@base == null (copy owns data)
var e = a.reshape(2, 5); // e.@base.Storage == a.Storage (view)
View Detection: Use arr.@base != null or arr.Storage.IsView to
detect if an array is a view. Note that arr.@base != null may trigger NDArray's
operator overloading for element-wise comparison. Prefer arr.Storage.IsView for
simple boolean checks.
Semantic Difference from NumPy: In NumPy, c.base is a returns True
(object identity). In NumSharp, c.@base creates a new wrapper each call, so
ReferenceEquals(c.@base, a) is false. However, the underlying storage
is the same: c.@base.Storage == a.Storage is true.
Memory Safety: The underlying memory is kept alive by the shared Disposer in the MemoryBlock, not by this property. Views remain valid even if the original array reference is garbage collected.
- See Also
dtype
The dtype of this array.
public Type dtype { get; }
Property Value
dtypesize
public int dtypesize { get; }
Property Value
flat
A 1-D iterator over the array.
public NDArray flat { get; }
Property Value
Remarks
ndim
Dimension count
public int ndim { get; }
Property Value
order
public char order { get; }
Property Value
shape
Data length of every dimension
public long[] shape { get; set; }
Property Value
- long[]
size
Total of elements
public long size { get; }
Property Value
strides
public long[] strides { get; }
Property Value
- long[]
typecode
The NPTypeCode of this array.
public NPTypeCode typecode { get; }
Property Value
Methods
AsGeneric<T>()
Tries to cast to NDArray<TDType>, otherwise creates an alias without reallocating data.
public NDArray<T> AsGeneric<T>() where T : unmanaged
Returns
- NDArray<T>
This NDArray as a generic version.
Type Parameters
TThe type of the generic
Exceptions
- InvalidOperationException
When
T!= dtype
AsOrMakeGeneric<T>()
Tries to cast to NDArray<TDType>, otherwise calls NDArray<T>.astype.
public NDArray<T> AsOrMakeGeneric<T>() where T : unmanaged
Returns
- NDArray<T>
This NDArray as a generic version.
Type Parameters
TThe type of the generic
Exceptions
- InvalidOperationException
When
T!= dtype
AsString(NDArray)
Converts the entire NDArray to a string.
public static string AsString(NDArray arr)
Parameters
arrNDArray
Returns
Remarks
Performs a copy due to String .net-framework limitations.
AsStringArray(NDArray)
Convert to String[] from NDArray
public static string[] AsStringArray(NDArray arr)
Parameters
arrNDArray
Returns
- string[]
Clone()
Clone the whole NDArray internal storage is also cloned into 2nd memory area
public NDArray Clone()
Returns
- NDArray
Cloned NDArray
CloneData()
public IArraySlice CloneData()
Returns
CloneData<T>()
public ArraySlice<T> CloneData<T>() where T : unmanaged
Returns
- ArraySlice<T>
Type Parameters
T
Contains(object)
Returns true if value is found in the array (linear search).
Equivalent to NumPy's value in arr.
public bool Contains(object value)
Parameters
valueobjectValue to search for.
Returns
- bool
True if value exists in the array.
Examples
var arr = np.array(new[] { 1, 2, 3, 4, 5 });
arr.Contains(3); // true
arr.Contains(10); // false
Remarks
This is a linear O(n) search. For sorted arrays, consider using np.searchsorted. NaN handling: NaN == NaN is false in IEEE 754, so Contains(float.NaN) returns false for arrays containing NaN. Use np.any(np.isnan(arr)) to check for NaN.
CopyTo(IMemoryBlock)
Copies the entire contents of this storage to given address (using Count).
public void CopyTo(IMemoryBlock slice)
Parameters
sliceIMemoryBlockThe slice to copy to.
CopyTo(nint)
Copies the entire contents of this storage to given address.
public void CopyTo(nint ptr)
Parameters
ptrnint
CopyTo(void*)
Copies the entire contents of this storage to given address (using Count).
public void CopyTo(void* address)
Parameters
addressvoid*The address to copy to.
CopyTo<T>(IMemoryBlock<T>)
Copies the entire contents of this storage to given address (using Count).
public void CopyTo<T>(IMemoryBlock<T> block) where T : unmanaged
Parameters
blockIMemoryBlock<T>The slice to copy to.
Type Parameters
T
CopyTo<T>(T*)
Copies the entire contents of this storage to given address.
public void CopyTo<T>(T* address) where T : unmanaged
Parameters
addressT*The address to copy to.
Type Parameters
T
CopyTo<T>(T[])
Copies the entire contents of this storage to given array.
public void CopyTo<T>(T[] array) where T : unmanaged
Parameters
arrayT[]The array to copy to.
Type Parameters
T
Data<T>()
Shortcut for access internal elements
public ArraySlice<T> Data<T>() where T : unmanaged
Returns
- ArraySlice<T>
Type Parameters
T
Equals(object)
Determines if NDArray data is same
public override bool Equals(object obj)
Parameters
objobjectNDArray to compare
Returns
- bool
if reference is same
ExpandEllipsis(object[], int)
protected static IEnumerable<object> ExpandEllipsis(object[] ndarrays, int ndim)
Parameters
Returns
FetchIndices(NDArray, NDArray[], NDArray, bool)
protected static NDArray FetchIndices(NDArray src, NDArray[] indices, NDArray @out, bool extraDim)
Parameters
Returns
FetchIndicesNDNonLinear<T>(NDArray<T>, NDArray[], int, long[], long[], NDArray)
Accepts collapsed
[SuppressMessage("ReSharper", "SuggestVarOrType_Elsewhere")]
protected static NDArray<T> FetchIndicesNDNonLinear<T>(NDArray<T> source, NDArray[] indices, int ndsCount, long[] retShape, long[] subShape, NDArray @out) where T : unmanaged
Parameters
Returns
- NDArray<T>
Type Parameters
T
FetchIndicesND<T>(NDArray<T>, NDArray<long>, NDArray[], int, long[], long[], NDArray)
Accepts collapsed
protected static NDArray<T> FetchIndicesND<T>(NDArray<T> src, NDArray<long> offsets, NDArray[] indices, int ndsCount, long[] retShape, long[] subShape, NDArray @out) where T : unmanaged
Parameters
srcNDArray<T>offsetsNDArray<long>indicesNDArray[]ndsCountintretShapelong[]subShapelong[]outNDArray
Returns
- NDArray<T>
Type Parameters
T
FetchIndices<T>(NDArray<T>, NDArray[], NDArray, bool)
protected static NDArray<T> FetchIndices<T>(NDArray<T> source, NDArray[] indices, NDArray @out, bool extraDim) where T : unmanaged
Parameters
Returns
- NDArray<T>
Type Parameters
T
FromMultiDimArray<T>(Array, bool)
Creates an NDArray out of given array of type T
public static NDArray FromMultiDimArray<T>(Array ndarray, bool copy = true) where T : unmanaged
Parameters
Returns
Type Parameters
T
FromString(string)
Converts a string to a vector ndarray of bytes.
public static NDArray FromString(string str)
Parameters
strstring
Returns
GetAtIndex(long)
Retrieves value of
public object GetAtIndex(long index)
Parameters
indexlong
Returns
GetAtIndex<T>(long)
Retrieves value of
public T GetAtIndex<T>(long index) where T : unmanaged
Parameters
indexlong
Returns
- T
Type Parameters
T
GetBoolean(int[])
Retrieves value of type bool.
public bool GetBoolean(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetBoolean(params long[])
public bool GetBoolean(params long[] indices)
Parameters
indiceslong[]
Returns
GetByte(int[])
Retrieves value of type byte.
public byte GetByte(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetByte(params long[])
public byte GetByte(params long[] indices)
Parameters
indiceslong[]
Returns
GetChar(int[])
Retrieves value of type char.
public char GetChar(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetChar(params long[])
public char GetChar(params long[] indices)
Parameters
indiceslong[]
Returns
GetComplex(int[])
public Complex GetComplex(int[] indices)
Parameters
indicesint[]
Returns
GetComplex(params long[])
public Complex GetComplex(params long[] indices)
Parameters
indiceslong[]
Returns
GetData()
Get reference to internal data storage
public IArraySlice GetData()
Returns
- IArraySlice
reference to internal storage as System.Array
GetData(int[])
Gets a NDArray at given indices.
public NDArray GetData(int[] indices)
Parameters
indicesint[]The coordinates to the wanted value
Returns
Remarks
Does not copy, returns a memory slice - this is similar to this[int[]]
GetData(long[])
Gets a NDArray at given indices.
public NDArray GetData(long[] indices)
Parameters
indiceslong[]The coordinates to the wanted value
Returns
Remarks
Does not copy, returns a memory slice - this is similar to this[long[]]
GetData<T>()
Gets the internal storage and converts it to T if necessary.
public ArraySlice<T> GetData<T>() where T : unmanaged
Returns
- ArraySlice<T>
An array of type
T
Type Parameters
TThe returned type.
GetDecimal(int[])
Retrieves value of type decimal.
public decimal GetDecimal(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetDecimal(params long[])
public decimal GetDecimal(params long[] indices)
Parameters
indiceslong[]
Returns
GetDouble(int[])
Retrieves value of type double.
public double GetDouble(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetDouble(params long[])
public double GetDouble(params long[] indices)
Parameters
indiceslong[]
Returns
GetEnumerator()
Returns an enumerator that iterates along the first axis.
public IEnumerator GetEnumerator()
Returns
Remarks
NumPy-compatible iteration behavior:
- 0-D arrays (scalars): throws TypeError
- 1-D arrays: yields scalar elements
- N-D arrays (N > 1): yields (N-1)-D NDArray slices along first axis
GetHalf(int[])
public Half GetHalf(int[] indices)
Parameters
indicesint[]
Returns
GetHalf(params long[])
public Half GetHalf(params long[] indices)
Parameters
indiceslong[]
Returns
GetHashCode()
NDArray is unhashable because it is mutable.
public override int GetHashCode()
Returns
- int
Never returns - always throws.
Remarks
NumPy arrays are unhashable because they are mutable. If an array were used as a dictionary key and then modified, the hash would change, breaking the dictionary's invariants.
This matches NumPy behavior:
>>> hash(np.array([1, 2, 3]))
TypeError: unhashable type: 'numpy.ndarray'
Workarounds:
- Use
arr.tobytes()as a hashable key (immutable snapshot) - Use
ReferenceEqualityComparer.Instancefor identity-based dictionaries - Convert to tuple:
tuple(arr.ToArray())
Exceptions
- NotSupportedException
Always thrown.
GetIndices(NDArray, NDArray[])
Used to perform selection based on indices, equivalent to nd[NDArray[]].
public NDArray GetIndices(NDArray @out, NDArray[] indices)
Parameters
Returns
Remarks
Exceptions
- IndexOutOfRangeException
When one of the indices exceeds limits.
- ArgumentException
indices must be of Int type (byte, u/short, u/int, u/long).
GetIndicesFromSlice(Shape, Slice, int)
Converts a slice to indices for the special case where slices are mixed with NDArrays in this[...]
protected static NDArray<long> GetIndicesFromSlice(Shape shape, Slice slice, int axis)
Parameters
Returns
GetIndicesFromSlice(long[], Slice, int)
Converts a slice to indices for the special case where slices are mixed with NDArrays in this[...]
protected static NDArray<long> GetIndicesFromSlice(long[] shape, Slice slice, int axis)
Parameters
Returns
GetInt16(int[])
Retrieves value of type short.
public short GetInt16(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetInt16(params long[])
public short GetInt16(params long[] indices)
Parameters
indiceslong[]
Returns
GetInt32(int[])
Retrieves value of type int.
public int GetInt32(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetInt32(params long[])
public int GetInt32(params long[] indices)
Parameters
indiceslong[]
Returns
GetInt64(int[])
Retrieves value of type long.
public long GetInt64(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetInt64(params long[])
public long GetInt64(params long[] indices)
Parameters
indiceslong[]
Returns
GetNDArrays(int)
Get all NDArray slices at that specific dimension.
[SuppressMessage("ReSharper", "LoopCanBeConvertedToQuery")]
public NDArray[] GetNDArrays(int axis = 0)
Parameters
axisintZero-based dimension index on which axis and forward of it to select data., e.g. dimensions=1, shape is (2,2,3,3), returned shape = 4 times of (3,3)
Returns
- NDArray[]
Examples
var nd = np.arange(27).reshape(3,1,3,3);
var ret = nd.GetNDArrays(1);
Assert.IsTrue(ret.All(n=>n.Shape == new Shape(3,3));
Assert.IsTrue(ret.Length == 3);
var nd = np.arange(27).reshape(3,1,3,3);
var ret = nd.GetNDArrays(0);
Assert.IsTrue(ret.All(n=>n.Shape == new Shape(1,3,3));
Assert.IsTrue(ret.Length == 3);
Remarks
Does not perform copy.
GetSByte(int[])
public sbyte GetSByte(int[] indices)
Parameters
indicesint[]
Returns
GetSByte(params long[])
public sbyte GetSByte(params long[] indices)
Parameters
indiceslong[]
Returns
GetSingle(int[])
Retrieves value of type float.
public float GetSingle(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetSingle(params long[])
public float GetSingle(params long[] indices)
Parameters
indiceslong[]
Returns
GetString(params long[])
Get a string out of a vector of chars.
public string GetString(params long[] indices)
Parameters
indiceslong[]
Returns
Remarks
Performs a copy due to String .net-framework limitations.
GetStringAt(long)
Get a string out of a vector of chars.
public string GetStringAt(long offset)
Parameters
offsetlong
Returns
Remarks
Performs a copy due to String .net-framework limitations.
GetUInt16(int[])
Retrieves value of type ushort.
public ushort GetUInt16(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetUInt16(params long[])
public ushort GetUInt16(params long[] indices)
Parameters
indiceslong[]
Returns
GetUInt32(int[])
Retrieves value of type uint.
public uint GetUInt32(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetUInt32(params long[])
public uint GetUInt32(params long[] indices)
Parameters
indiceslong[]
Returns
GetUInt64(int[])
Retrieves value of type ulong.
public ulong GetUInt64(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetUInt64(params long[])
public ulong GetUInt64(params long[] indices)
Parameters
indiceslong[]
Returns
GetValue(int[])
Retrieves value of unspecified type (will figure using DType).
public object GetValue(int[] indices)
Parameters
indicesint[]The shape's indices to get.
Returns
Exceptions
GetValue(params long[])
Retrieves value of unspecified type (will figure using DType).
public object GetValue(params long[] indices)
Parameters
indiceslong[]The shape's indices to get.
Returns
Exceptions
GetValue<T>(int[])
Retrieves value of unspecified type (will figure using DType).
public T GetValue<T>(int[] indices) where T : unmanaged
Parameters
indicesint[]The shape's indices to get.
Returns
- T
Type Parameters
T
Exceptions
GetValue<T>(params long[])
Get a single value from NDArray as type T.
public T GetValue<T>(params long[] indices) where T : unmanaged
Parameters
indiceslong[]The shape's indices to get.
Returns
- T
Type Parameters
T
Exceptions
MakeGeneric<T>()
Creates an alias without reallocating data.
public NDArray<T> MakeGeneric<T>() where T : unmanaged
Returns
- NDArray<T>
This NDArray as a generic version.
Type Parameters
TThe type of the generic
Exceptions
- InvalidOperationException
When
T!= dtype
Normalize()
Normalizes all entries into the range between 0 and 1
Note: this is not a numpy function.
public void Normalize()
NormalizeIndexArray(NDArray)
Normalizes an index array for fancy indexing. NumPy accepts all integer types (int8/16/32/64, uint8/16/32/64) for indexing. Non-integer types (float, decimal, char, bool) raise IndexError. We keep Int32/Int64 as-is; other integer types are converted to Int64.
protected static NDArray NormalizeIndexArray(NDArray indices)
Parameters
indicesNDArrayThe index array to normalize.
Returns
- NDArray
The normalized index array (Int32 or Int64).
Exceptions
- IndexOutOfRangeException
When the index array is not an integer type.
PrepareIndexGetters(Shape, NDArray[])
Generates index getter function based on given indices.
protected static Func<long, long>[] PrepareIndexGetters(Shape srcShape, NDArray[] indices)
Parameters
Returns
ReplaceData(IArraySlice)
Sets values as the internal data source and changes the internal storage data type to values type.
public void ReplaceData(IArraySlice values)
Parameters
valuesIArraySlice
Remarks
Does not copy values and doesn't change shape.
ReplaceData(IArraySlice, Type)
Sets values as the internal data source and changes the internal storage data type to values type.
public void ReplaceData(IArraySlice values, Type dtype)
Parameters
valuesIArraySlicedtypeType
Remarks
Does not copy values and doesn't change shape.
ReplaceData(NDArray)
Sets nd as the internal data storage and changes the internal storage data type to nd type.
public void ReplaceData(NDArray nd)
Parameters
ndNDArray
Remarks
Does not copy values and does change shape and dtype.
ReplaceData(Array)
Sets values as the internal data storage and changes the internal storage data type to values type.
public void ReplaceData(Array values)
Parameters
valuesArray
Remarks
Does not copy values.
ReplaceData(Array, NPTypeCode)
Set an Array to internal storage, cast it to new dtype and if necessary change dtype
public void ReplaceData(Array values, NPTypeCode typeCode)
Parameters
valuesArraytypeCodeNPTypeCode
Remarks
Does not copy values unless cast is necessary and doesn't change shape.
ReplaceData(Array, Type)
Sets values as the internal data storage and changes the internal storage data type to dtype and casts values if necessary.
public void ReplaceData(Array values, Type dtype)
Parameters
valuesArrayThe values to set as internal data soruce
dtypeTypeThe type to change this storage to and the type to cast values if necessary.
Remarks
Does not copy values unless cast is necessary.
Scalar(object)
public static NDArray Scalar(object value)
Parameters
valueobjectThe value of the scalar
Returns
Remarks
In case when value is not dtype, Converts.ChangeType(object,System.Type) will be called.
Scalar(object, NPTypeCode)
public static NDArray Scalar(object value, NPTypeCode typeCode)
Parameters
valueobjectThe value of the scalar
typeCodeNPTypeCodeThe type code of the scalar.
Returns
Remarks
In case when value is not dtype, Converts.ChangeType(object,System.Type) will be called.
Scalar(object, Type)
public static NDArray Scalar(object value, Type dtype)
Parameters
Returns
Remarks
In case when value is not dtype, Converts.ChangeType(object,System.Type) will be called.
Scalar<T>(object)
public static NDArray Scalar<T>(object value) where T : unmanaged
Parameters
valueobjectThe value of the scalar, attempt to convert will be performed
Returns
Type Parameters
T
Remarks
In case when value is not dtype, Converts.ChangeType(object,System.Type) will be called.
Scalar<T>(T)
public static NDArray Scalar<T>(T value) where T : unmanaged
Parameters
valueTThe value of the scalar
Returns
Type Parameters
T
Remarks
In case when value is not dtype, Converts.ChangeType(object,System.Type) will be called.
SetAtIndex(object, long)
Retrieves value at given linear (offset) index.
public void SetAtIndex(object obj, long index)
Parameters
SetAtIndex<T>(T, long)
Retrieves value of
public void SetAtIndex<T>(T value, long index) where T : unmanaged
Parameters
valueTindexlong
Type Parameters
T
SetBoolean(bool, int[])
Sets a bool at specific coordinates.
public void SetBoolean(bool value, int[] indices)
Parameters
SetBoolean(bool, params long[])
Sets a bool at specific coordinates.
public void SetBoolean(bool value, params long[] indices)
Parameters
SetByte(byte, int[])
Sets a byte at specific coordinates.
public void SetByte(byte value, int[] indices)
Parameters
SetByte(byte, params long[])
Sets a byte at specific coordinates.
public void SetByte(byte value, params long[] indices)
Parameters
SetChar(char, int[])
Sets a char at specific coordinates.
public void SetChar(char value, int[] indices)
Parameters
SetChar(char, params long[])
Sets a char at specific coordinates.
public void SetChar(char value, params long[] indices)
Parameters
SetComplex(Complex, int[])
public void SetComplex(Complex value, int[] indices)
Parameters
SetComplex(Complex, params long[])
public void SetComplex(Complex value, params long[] indices)
Parameters
SetData(IArraySlice, int[])
Set a IArraySlice at given indices.
public void SetData(IArraySlice value, int[] indices)
Parameters
valueIArraySliceThe value to set
indicesint[]The
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetData(IArraySlice, params long[])
Set a IArraySlice at given indices (long version).
public void SetData(IArraySlice value, params long[] indices)
Parameters
valueIArraySliceThe value to set
indiceslong[]The indices (long version)
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetData(NDArray, int[])
Set a NDArray at given indices.
public void SetData(NDArray value, int[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetData(NDArray, params long[])
Set a NDArray at given indices (long version).
public void SetData(NDArray value, params long[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetData(object)
public void SetData(object p)
Parameters
pobject
SetData(object, int[])
Set a NDArray, IArraySlice, Array or a scalar value at given indices.
public void SetData(object value, int[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetDecimal(decimal, int[])
Sets a decimal at specific coordinates.
public void SetDecimal(decimal value, int[] indices)
Parameters
SetDecimal(decimal, params long[])
Sets a decimal at specific coordinates.
public void SetDecimal(decimal value, params long[] indices)
Parameters
SetDouble(double, int[])
Sets a double at specific coordinates.
public void SetDouble(double value, int[] indices)
Parameters
SetDouble(double, params long[])
Sets a double at specific coordinates.
public void SetDouble(double value, params long[] indices)
Parameters
SetHalf(Half, int[])
public void SetHalf(Half value, int[] indices)
Parameters
SetHalf(Half, params long[])
public void SetHalf(Half value, params long[] indices)
Parameters
SetIndices(NDArray, NDArray[])
Used to perform set a selection based on indices, equivalent to nd[NDArray[]] = values.
public void SetIndices(NDArray values, NDArray[] indices)
Parameters
Remarks
Exceptions
- IndexOutOfRangeException
When one of the indices exceeds limits.
- ArgumentException
indices must be of Int type (byte, u/short, u/int, u/long).
- NumSharpException
If this array is not writeable (e.g., broadcast array).
SetIndices(NDArray, NDArray[], NDArray)
protected static void SetIndices(NDArray src, NDArray[] indices, NDArray values)
Parameters
SetIndices(object[], NDArray)
protected void SetIndices(object[] indicesObjects, NDArray values)
Parameters
SetIndicesNDNonLinear<T>(NDArray<T>, NDArray[], int, long[], long[], NDArray<T>)
Accepts collapsed
[SuppressMessage("ReSharper", "SuggestVarOrType_Elsewhere")]
protected static void SetIndicesNDNonLinear<T>(NDArray<T> source, NDArray[] indices, int ndsCount, long[] retShape, long[] subShape, NDArray<T> values) where T : unmanaged
Parameters
Type Parameters
T
SetIndicesND<T>(NDArray<T>, NDArray<long>, NDArray[], int, long[], long[], NDArray<T>)
Accepts collapsed
protected static void SetIndicesND<T>(NDArray<T> dst, NDArray<long> dstOffsets, NDArray[] dstIndices, int ndsCount, long[] retShape, long[] subShape, NDArray<T> values) where T : unmanaged
Parameters
dstNDArray<T>dstOffsetsNDArray<long>dstIndicesNDArray[]ndsCountintretShapelong[]subShapelong[]valuesNDArray<T>
Type Parameters
T
SetIndices<T>(NDArray<T>, NDArray[], NDArray)
protected static void SetIndices<T>(NDArray<T> source, NDArray[] indices, NDArray values) where T : unmanaged
Parameters
Type Parameters
T
SetInt16(short, int[])
Sets a short at specific coordinates.
public void SetInt16(short value, int[] indices)
Parameters
SetInt16(short, params long[])
Sets a short at specific coordinates.
public void SetInt16(short value, params long[] indices)
Parameters
SetInt32(int, int[])
Sets a int at specific coordinates.
public void SetInt32(int value, int[] indices)
Parameters
SetInt32(int, params long[])
Sets a int at specific coordinates.
public void SetInt32(int value, params long[] indices)
Parameters
SetInt64(long, int[])
Sets a long at specific coordinates.
public void SetInt64(long value, int[] indices)
Parameters
SetInt64(long, params long[])
Sets a long at specific coordinates.
public void SetInt64(long value, params long[] indices)
Parameters
SetSByte(sbyte, int[])
public void SetSByte(sbyte value, int[] indices)
Parameters
SetSByte(sbyte, params long[])
public void SetSByte(sbyte value, params long[] indices)
Parameters
SetSingle(float, int[])
Sets a float at specific coordinates.
public void SetSingle(float value, int[] indices)
Parameters
SetSingle(float, params long[])
Sets a float at specific coordinates.
public void SetSingle(float value, params long[] indices)
Parameters
SetString(string, params long[])
public void SetString(string value, params long[] indices)
Parameters
SetStringAt(string, long)
public void SetStringAt(string value, long offset)
Parameters
SetUInt16(ushort, int[])
Sets a ushort at specific coordinates.
public void SetUInt16(ushort value, int[] indices)
Parameters
SetUInt16(ushort, params long[])
Sets a ushort at specific coordinates.
public void SetUInt16(ushort value, params long[] indices)
Parameters
SetUInt32(uint, int[])
Sets a uint at specific coordinates.
public void SetUInt32(uint value, int[] indices)
Parameters
SetUInt32(uint, params long[])
Sets a uint at specific coordinates.
public void SetUInt32(uint value, params long[] indices)
Parameters
SetUInt64(ulong, int[])
Sets a ulong at specific coordinates.
public void SetUInt64(ulong value, int[] indices)
Parameters
SetUInt64(ulong, params long[])
Sets a ulong at specific coordinates.
public void SetUInt64(ulong value, params long[] indices)
Parameters
SetValue(object, int[])
Set a single value at given indices.
public void SetValue(object value, int[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetValue(object, params long[])
Set a single value at given indices.
public void SetValue(object value, params long[] indices)
Parameters
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetValue<T>(T, int[])
Set a single value at given indices.
public void SetValue<T>(T value, int[] indices) where T : unmanaged
Parameters
valueTThe value to set
indicesint[]The
Type Parameters
T
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
SetValue<T>(T, params long[])
Set a single value at given indices.
public void SetValue<T>(T value, params long[] indices) where T : unmanaged
Parameters
valueTThe value to set
indiceslong[]The coordinates (long version).
Type Parameters
T
Remarks
Does not change internal storage data type.
If value does not match DType, value will be converted.
ToArray<T>()
public T[] ToArray<T>() where T : unmanaged
Returns
- T[]
Type Parameters
T
ToByteArray()
public byte[] ToByteArray()
Returns
- byte[]
ToJaggedArray<T>()
public Array ToJaggedArray<T>() where T : unmanaged
Returns
Type Parameters
T
ToMuliDimArray<T>()
public Array ToMuliDimArray<T>() where T : unmanaged
Returns
Type Parameters
T
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
ToString(bool)
public string ToString(bool flat)
Parameters
flatbool
Returns
__contains__(object)
Python-compatible contains method. Equivalent to Contains(object).
public bool __contains__(object value)
Parameters
valueobjectValue to search for.
Returns
- bool
True if value exists in the array.
Remarks
This method exists for Python interoperability and naming consistency.
In Python: value in arr calls arr.contains(value)
__getitem__(int)
Python-compatible getitem method with integer index.
public NDArray __getitem__(int index)
Parameters
indexintIndex along the first axis.
Returns
- NDArray
Element or slice at the given index.
Remarks
Equivalent to arr[index] in Python.
Supports negative indexing (-1 = last element).
__getitem__(params int[])
Python-compatible getitem method with params indices.
public NDArray __getitem__(params int[] indices)
Parameters
indicesint[]Indices for each dimension.
Returns
- NDArray
Element or slice at the given indices.
__getitem__(long)
Python-compatible getitem method with long index.
public NDArray __getitem__(long index)
Parameters
indexlongIndex along the first axis.
Returns
- NDArray
Element or slice at the given index.
__getitem__(string)
Python-compatible getitem method with slice string.
public NDArray __getitem__(string slice)
Parameters
slicestringSlice specification (e.g., "1:3", "::-1", "..., 0").
Returns
- NDArray
Sliced view of the array.
Remarks
Equivalent to arr[slice] in Python.
Examples:
arr.__getitem__(":3") // First 3 elements
arr.__getitem__("1:-1") // All but first and last
arr.__getitem__("::-1") // Reversed
arr.__getitem__("..., 0") // All rows, first column
__hash__()
Python-compatible hash method. NDArray is unhashable because it is mutable.
public int __hash__()
Returns
- int
Never returns - always throws.
Remarks
This method exists for Python interoperability and naming consistency.
In Python: hash(arr) calls arr.hash()
NumPy behavior:
>>> arr = np.array([1, 2, 3])
>>> hash(arr)
TypeError: unhashable type: 'numpy.ndarray'
Exceptions
- NotSupportedException
Always thrown.
__iter__()
Python-compatible iter method. Returns an enumerator over the first axis.
public IEnumerator __iter__()
Returns
- IEnumerator
Enumerator yielding NDArray slices along the first axis.
Remarks
This matches NumPy behavior:
>>> for row in np.array([[1, 2], [3, 4]]):
... print(row)
[1 2]
[3 4]
For 1-D arrays, iterates over scalar elements. For N-D arrays, iterates over (N-1)-D slices.
__len__()
Python-compatible len method. Returns the length of the first dimension (like Python's len()).
public long __len__()
Returns
- long
Length of the first dimension, or 1 for scalars.
Remarks
This matches NumPy behavior:
>>> len(np.array([1, 2, 3]))
3
>>> len(np.array([[1, 2], [3, 4]]))
2 # First dimension
>>> len(np.array(5))
TypeError: len() of unsized object
Note: For scalars (0-d arrays), NumPy raises TypeError. NumSharp returns 1 for consistency with C# conventions. Use size for total element count.
__setitem__(int, object)
Python-compatible setitem method with integer index.
public void __setitem__(int index, object value)
Parameters
__setitem__(long, object)
Python-compatible setitem method with long index.
public void __setitem__(long index, object value)
Parameters
__setitem__(string, object)
Python-compatible setitem method with slice string.
public void __setitem__(string slice, object value)
Parameters
amax(int, bool, Type)
Return the maximum of an array or maximum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray amax(int axis, bool keepdims = false, Type dtype = null)
Parameters
axisintAxis or axes along which to operate.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
amax(Type)
Return the maximum of an array or maximum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray amax(Type dtype = null)
Parameters
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
amax<T>()
Return the maximum of an array or maximum along an axis.
public T amax<T>() where T : unmanaged
Returns
- T
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Type Parameters
TThe expected return type, cast will be performed if necessary.
Remarks
amin(int, bool, Type)
Return the minimum of an array or minimum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray amin(int axis, bool keepdims = false, Type dtype = null)
Parameters
axisintAxis or axes along which to operate.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
amin(Type)
Return the minimum of an array or minimum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray amin(Type dtype = null)
Parameters
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
amin<T>()
Return the minimum of an array or minimum along an axis.
public T amin<T>() where T : unmanaged
Returns
- T
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Type Parameters
TThe expected return type, cast will be performed if necessary.
Remarks
argmax()
Returns the index of the maximum value (flattened array).
public long argmax()
Returns
- long
The index of the maximal value in the flattened array.
Remarks
argmax(int, bool)
Returns the indices of the maximum values along an axis.
public NDArray argmax(int axis, bool keepdims = false)
Parameters
axisintThe axis along which to operate. By default, the index is into the flattened array.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one.
Returns
- NDArray
Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed (unless keepdims is True).
Remarks
argmin()
Returns the index of the minimum value (flattened array).
public long argmin()
Returns
- long
The index of the minimum value in the flattened array.
Remarks
argmin(int, bool)
Returns the indices of the minimum values along an axis.
public NDArray argmin(int axis, bool keepdims = false)
Parameters
axisintThe axis along which to operate. By default, the index is into the flattened array.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one.
Returns
- NDArray
Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed (unless keepdims is True).
Remarks
argsort<T>(int)
Returns the indices that would sort an array.
Perform an indirect sort along the given axis using the algorithm specified by the kind keyword. It returns an array of indices of the same shape as a that index data along the given axis in sorted order. Supports arrays with >2B elements using long indexing.
public NDArray argsort<T>(int axis = -1) where T : unmanaged
Parameters
axisint
Returns
Type Parameters
T
array_equal(NDArray)
True if two arrays have the same shape and elements, False otherwise.
public bool array_equal(NDArray rhs)
Parameters
rhsNDArrayInput array.
Returns
- bool
Returns True if the arrays are equal.
Remarks
astype(NPTypeCode, bool)
Copy of the array, cast to a specified type.
public NDArray astype(NPTypeCode typeCode, bool copy = true)
Parameters
typeCodeNPTypeCodecopyboolBy default, astype always returns a newly allocated array. If this is set to false, the input internal array is replaced instead of returning a new NDArray with the casted data.
Returns
Remarks
astype(Type, bool)
Copy of the array, cast to a specified type.
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray astype(Type dtype, bool copy = true)
Parameters
dtypeTypeThe dtype to cast this array.
copyboolBy default, astype always returns a newly allocated array. If this is set to false, the input internal array is replaced instead of returning a new NDArray with the casted data.
Returns
Remarks
convolve(NDArray, string)
Returns the discrete, linear convolution of two one-dimensional sequences.
The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal[1]. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions.
If v is longer than a, the arrays are swapped before computation.
public NDArray convolve(NDArray v, string mode = "full")
Parameters
vNDArrayThe second one-dimensional input array.
modestring'full', 'same', or 'valid'. Default is 'full'.
Returns
- NDArray
Discrete, linear convolution of a and v.
Remarks
NumPy Reference: https://numpy.org/doc/stable/reference/generated/numpy.convolve.html
The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
copy(char)
Return a copy of the array.
public NDArray copy(char order = 'C')
Parameters
orderchar
Returns
Remarks
cumsum(int?, Type)
Return the cumulative sum of the elements along a given axis.
public NDArray cumsum(int? axis = null, Type dtype = null)
Parameters
axisint?Axis along which the cumulative sum is computed. The default (-1) is to compute the cumsum over the flattened array.
dtypeTypeType of the returned array and of the accumulator in which the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.
Returns
- NDArray
A new array holding the result is returned unless out is specified, in which case a reference to out is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.
Remarks
delete(IEnumerable)
public NDArray delete(IEnumerable delete)
Parameters
deleteIEnumerable
Returns
dot(NDArray)
Dot product of two arrays. See remarks.
public NDArray dot(NDArray b)
Parameters
bNDArrayRhs, Second argument.
Returns
- NDArray
Returns the dot product of a and b. If a and b are both scalars or both 1-D arrays then a scalar is returned; otherwise an array is returned. If out is given, then it is returned.
Remarks
https://numpy.org/doc/stable/reference/generated/numpy.dot.html
Specifically,
- If both a and b are 1-D arrays, it is inner product of vectors (without complex conjugation).
- If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred.
- If either a or b is 0-D(scalar), it is equivalent to multiply and using numpy.multiply(a, b) or a* b is preferred.
- If a is an N-D array and b is a 1-D array, it is a sum product over the last axis of a and b.
- If a is an N-D array and b is an M-D array(where M>=2), it is a sum product over the last axis of a and the second-to-last axis of b:
dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
dstack(params NDArray[])
Stack arrays in sequence depth wise (along third axis). This is equivalent to concatenation along the third axis after 2-D arrays of shape(M, N) have been reshaped to(M, N,1) and 1-D arrays of shape(N,) have been reshaped to(1, N,1). Rebuilds arrays divided by dsplit. This function makes most sense for arrays with up to 3 dimensions.For instance, for pixel-data with a height(first axis), width(second axis), and r/g/b channels(third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.
public NDArray dstack(params NDArray[] tup)
Parameters
tupNDArray[]The arrays must have the same shape along all but the third axis. 1-D or 2-D arrays must have the same shape.
Returns
- NDArray
The array formed by stacking the given arrays, will be at least 3-D.
Remarks
flatten(char)
Return a copy of the array collapsed into one dimension.
public NDArray flatten(char order = 'C')
Parameters
ordercharThe order in which to read the elements. 'C' means row-major (C-style), 'F' means column-major (Fortran-style). NumSharp only supports 'C' order; this parameter is accepted for API compatibility but 'F' is ignored.
Returns
- NDArray
A copy of the input array, flattened to one dimension.
Remarks
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html NumPy: flatten() ALWAYS returns a copy. Use ravel() for a view when possible.
hstack(params NDArray[])
Stack arrays in sequence horizontally (column wise). This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis.Rebuilds arrays divided by hsplit. This function makes most sense for arrays with up to 3 dimensions.For instance, for pixel-data with a height(first axis), width(second axis), and r/g/b channels(third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.
public NDArray hstack(params NDArray[] tup)
Parameters
tupNDArray[]The arrays must have the same shape along all but the second axis, except 1-D arrays which can be any length.
Returns
- NDArray
The array formed by stacking the given arrays.
Remarks
inv()
public NDArray inv()
Returns
item()
Copy an element of an array to a standard Python scalar and return it.
public object item()
Returns
- object
A copy of the specified element of the array as a suitable Python scalar.
Remarks
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.item.html
When called without arguments, works only for arrays with one element (size 1), which can have any shape (0-d, 1-element 1-d, 1x1 2-d, etc.).
This is the NumPy 2.x replacement for the deprecated np.asscalar().
Exceptions
- IncorrectSizeException
If array size is not 1.
item(long)
Copy an element of an array to a standard Python scalar and return it.
public object item(long index)
Parameters
indexlongFlat index of element to extract (supports negative indexing).
Returns
- object
A copy of the specified element of the array as a suitable Python scalar.
Remarks
item(long, long)
Copy an element of an array to a standard Python scalar and return it.
public object item(long i, long j)
Parameters
Returns
- object
A copy of the specified element of the array as a suitable Python scalar.
Remarks
item(long, long, long)
Copy an element of an array to a standard Python scalar and return it.
public object item(long i, long j, long k)
Parameters
ilongIndex along first dimension.
jlongIndex along second dimension.
klongIndex along third dimension.
Returns
- object
A copy of the specified element of the array as a suitable Python scalar.
Remarks
item(params long[])
Copy an element of an array to a standard Python scalar and return it.
public object item(params long[] indices)
Parameters
indiceslong[]Indices of element to extract (one per dimension).
Returns
- object
A copy of the specified element of the array as a suitable Python scalar.
Remarks
item<T>()
Copy an element of an array to a standard Python scalar and return it.
public T item<T>() where T : unmanaged
Returns
- T
A copy of the specified element of the array as a typed scalar.
Type Parameters
TThe type to convert the value to.
Exceptions
- IncorrectSizeException
If array size is not 1.
item<T>(long)
Copy an element of an array to a standard Python scalar and return it.
public T item<T>(long index) where T : unmanaged
Parameters
indexlongFlat index of element to extract (supports negative indexing).
Returns
- T
A copy of the specified element of the array as a typed scalar.
Type Parameters
TThe type to convert the value to.
item<T>(long, long)
Copy an element of an array to a standard Python scalar and return it.
public T item<T>(long i, long j) where T : unmanaged
Parameters
Returns
- T
A copy of the specified element of the array as a typed scalar.
Type Parameters
TThe type to convert the value to.
item<T>(long, long, long)
Copy an element of an array to a standard Python scalar and return it.
public T item<T>(long i, long j, long k) where T : unmanaged
Parameters
ilongIndex along first dimension.
jlongIndex along second dimension.
klongIndex along third dimension.
Returns
- T
A copy of the specified element of the array as a typed scalar.
Type Parameters
TThe type to convert the value to.
item<T>(params long[])
Copy an element of an array to a standard Python scalar and return it.
public T item<T>(params long[] indices) where T : unmanaged
Parameters
indiceslong[]Indices of element to extract (one per dimension).
Returns
- T
A copy of the specified element of the array as a typed scalar.
Type Parameters
TThe type to convert the value to.
itemset(Shape, object)
Insert scalar into an array (scalar is cast to array’s dtype, if possible)
public void itemset(Shape shape, object val)
Parameters
Remarks
itemset(ref Shape, object)
Insert scalar into an array (scalar is cast to array’s dtype, if possible)
public void itemset(ref Shape shape, object val)
Parameters
Remarks
itemset(int[], object)
Insert scalar into an array (scalar is cast to array’s dtype, if possible)
public void itemset(int[] shape, object val)
Parameters
Remarks
itemset<T>(int[], T)
Insert scalar into an array (scalar is cast to array’s dtype, if possible)
public void itemset<T>(int[] shape, T val) where T : unmanaged
Parameters
shapeint[]valT
Type Parameters
T
Remarks
lstqr(NDArray, double)
Least Square method
Determines NDArray X which reduces least square error of Linear System A * X = B. This NDArray is equal to A.
public NDArray lstqr(NDArray nDArrayB, double rcon = 0.0001)
Parameters
Returns
- NDArray
NArray X
matrix_power(int)
public NDArray matrix_power(int power)
Parameters
powerint
Returns
max(int, bool, Type)
Return the maximum of an array or maximum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray max(int axis, bool keepdims = false, Type dtype = null)
Parameters
axisintAxis or axes along which to operate.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
max(Type)
Return the maximum of an array or maximum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray max(Type dtype = null)
Parameters
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
max<T>()
Return the maximum of an array or maximum along an axis.
public T max<T>() where T : unmanaged
Returns
- T
Maximum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Type Parameters
TThe expected return type, cast will be performed if necessary.
Remarks
mean()
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
public NDArray mean()
Returns
- NDArray
returns a new array containing the mean values, otherwise a reference to the output array is returned.
Remarks
mean(int)
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
public NDArray mean(int axis)
Parameters
axisintAxis or axes along which the means are computed. The default is to compute the mean of the flattened array.
Returns
- NDArray
returns a new array containing the mean values, otherwise a reference to the output array is returned.
Remarks
mean(int, NPTypeCode, bool)
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
public NDArray mean(int axis, NPTypeCode type, bool keepdims = false)
Parameters
axisintAxis or axes along which the means are computed. The default is to compute the mean of the flattened array.
typeNPTypeCodeType to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be.If the sub-class’ method does not implement keepdims any exceptions will be raised.
Returns
- NDArray
returns a new array containing the mean values, otherwise a reference to the output array is returned.
Remarks
mean(int, bool)
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
public NDArray mean(int axis, bool keepdims)
Parameters
axisintAxis or axes along which the means are computed. The default is to compute the mean of the flattened array.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be.If the sub-class’ method does not implement keepdims any exceptions will be raised.
Returns
- NDArray
returns a new array containing the mean values, otherwise a reference to the output array is returned.
mean(int, Type, bool)
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.
public NDArray mean(int axis, Type type, bool keepdims = false)
Parameters
axisintAxis or axes along which the means are computed. The default is to compute the mean of the flattened array.
typeTypeType to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be.If the sub-class’ method does not implement keepdims any exceptions will be raised.
Returns
- NDArray
returns a new array containing the mean values, otherwise a reference to the output array is returned.
Remarks
mgrid(NDArray)
nd_grid instance which returns a dense multi-dimensional “meshgrid”. An instance of numpy.lib.index_tricks.nd_grid which returns an dense (or fleshed out) mesh-grid when indexed, so that each returned argument has the same shape. The dimensions and number of the output arrays are equal to the number of indexing dimensions.If the step length is not a complex number, then the stop is not inclusive.
public (NDArray, NDArray) mgrid(NDArray rhs)
Parameters
rhsNDArray
Returns
Remarks
min(int, bool, Type)
Return the minimum of an array or minimum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray min(int axis, bool keepdims = false, Type dtype = null)
Parameters
axisintAxis or axes along which to operate.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
min(Type)
Return the minimum of an array or minimum along an axis.
[SuppressMessage("ReSharper", "TooWideLocalVariableScope")]
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray min(Type dtype = null)
Parameters
dtypeTypethe type expected as a return, null will remain the same dtype.
Returns
- NDArray
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Remarks
min<T>()
Return the minimum of an array or minimum along an axis.
public T min<T>() where T : unmanaged
Returns
- T
Minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.
Type Parameters
TThe expected return type, cast will be performed if necessary.
Remarks
multi_dot(params NDArray[])
public NDArray multi_dot(params NDArray[] np2Multi)
Parameters
np2MultiNDArray[]
Returns
negate()
Negates all values by performing: -x
public NDArray negate()
Returns
negative()
Numerical negative, element-wise. Returns -x for each element (negates ALL values, not just positive).
public NDArray negative()
Returns
Remarks
positive()
Numerical positive, element-wise. This is an identity operation - returns +x (a copy of the input). Equivalent to np.array(a, copy=True).
public NDArray positive()
Returns
Remarks
prod(int?, Type, bool)
Return the product of array elements over a given axis.
public NDArray prod(int? axis = null, Type dtype = null, bool keepdims = false)
Parameters
axisint?Axis or axes along which a product is performed. The default, axis=None, will calculate the product of all the elements in the input array. If axis is negative it counts from the last to the first axis.
dtypeTypeThe type of the returned array, as well as of the accumulator in which the elements are multiplied. The dtype of a is used by default unless a has an integer dtype of less precision than the default platform integer. In that case, if a is signed then the platform integer is used while if a is unsigned then an unsigned integer of the same precision as the platform integer is used.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
Returns
- NDArray
An array shaped as a but with the specified axis removed.
Remarks
qr()
public (NDArray, NDArray) qr()
Returns
ravel()
Return a contiguous flattened array. A 1-D array, containing the elements of the input, is returned
public NDArray ravel()
Returns
Remarks
reshape(Shape)
Gives a new shape to an array without changing its data.
public NDArray reshape(Shape newShape)
Parameters
newShapeShapeThe new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape(ref Shape)
Gives a new shape to an array without changing its data.
public NDArray reshape(ref Shape newShape)
Parameters
newShapeShapeThe new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape(int[])
Gives a new shape to an array without changing its data.
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape(int[] shape)
Parameters
shapeint[]The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape(params long[])
Gives a new shape to an array without changing its data.
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape(params long[] shape)
Parameters
shapelong[]The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape_unsafe(Shape)
Gives a new shape to an array without changing its data.
public NDArray reshape_unsafe(Shape newshape)
Parameters
newshapeShapeThe new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape_unsafe(ref Shape)
Gives a new shape to an array without changing its data.
public NDArray reshape_unsafe(ref Shape newshape)
Parameters
newshapeShapeThe new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape_unsafe(int[])
Gives a new shape to an array without changing its data.
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape_unsafe(int[] shape)
Parameters
shapeint[]The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
reshape_unsafe(params long[])
Gives a new shape to an array without changing its data.
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public NDArray reshape_unsafe(params long[] shape)
Parameters
shapelong[]The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Returns
- NDArray
This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array.
Remarks
roll(int)
Roll array elements along a given axis.
Elements that roll beyond the last position are re-introduced at the first. The array is flattened before shifting, after which the original shape is restored.
public NDArray roll(int shift)
Parameters
shiftintThe number of places by which elements are shifted.
Returns
- NDArray
Output array, with the same shape as the input.
Remarks
roll(int, int)
Roll array elements along a given axis.
Elements that roll beyond the last position are re-introduced at the first.
public NDArray roll(int shift, int axis)
Parameters
shiftintThe number of places by which elements are shifted.
axisintAxis along which elements are shifted.
Returns
- NDArray
Output array, with the same shape as the input.
Remarks
roll(long)
Roll array elements along a given axis.
Elements that roll beyond the last position are re-introduced at the first. The array is flattened before shifting, after which the original shape is restored.
public NDArray roll(long shift)
Parameters
shiftlongThe number of places by which elements are shifted.
Returns
- NDArray
Output array, with the same shape as the input.
Remarks
roll(long, int)
Roll array elements along a given axis.
Elements that roll beyond the last position are re-introduced at the first.
public NDArray roll(long shift, int axis)
Parameters
shiftlongThe number of places by which elements are shifted.
axisintAxis along which elements are shifted.
Returns
- NDArray
Output array, with the same shape as the input.
Remarks
std(bool, int?, NPTypeCode?)
Compute the standard deviation along the specified axis. Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
public NDArray std(bool keepdims = false, int? ddof = null, NPTypeCode? dtype = null)
Parameters
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
ddofint?Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
dtypeNPTypeCode?
Returns
- NDArray
returns a new array containing the std values, otherwise a reference to the output array is returned.
Remarks
std(int, bool, int?, NPTypeCode?)
Compute the standard deviation along the specified axis. Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
public NDArray std(int axis, bool keepdims = false, int? ddof = null, NPTypeCode? dtype = null)
Parameters
axisintAxis or axes along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
ddofint?Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
dtypeNPTypeCode?
Returns
- NDArray
returns a new array containing the std values, otherwise a reference to the output array is returned.
Remarks
sum()
Sum of array elements into a scalar.
public NDArray sum()
Returns
- NDArray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.
Remarks
sum(int)
Sum of array elements over a given axis.
public NDArray sum(int axis)
Parameters
axisintAxis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.
Returns
- NDArray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.
Remarks
sum(int, bool, NPTypeCode?)
Sum of array elements over a given axis.
public NDArray sum(int axis, bool keepdims, NPTypeCode? typeCode = null)
Parameters
axisintAxis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the sum method of sub-classes of ndarray, however any non-default value will be.If the sub-class’ method does not implement keepdims any exceptions will be raised.
typeCodeNPTypeCode?The type of the returned array and of the accumulator in which the elements are summed. The dtype of a is used by default unless a has an integer dtype of less precision than the default platform integer. In that case, if a is signed then the platform integer is used while if a is unsigned then an unsigned integer of the same precision as the platform integer is used.
Returns
- NDArray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.
Remarks
sum(int, bool, Type)
Sum of array elements over a given axis.
public NDArray sum(int axis, bool keepdims, Type dtype)
Parameters
axisintAxis or axes along which a sum is performed. The default, axis=None, will sum all of the elements of the input array. If axis is negative it counts from the last to the first axis.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the sum method of sub-classes of ndarray, however any non-default value will be.If the sub-class’ method does not implement keepdims any exceptions will be raised.
dtypeTypeThe type of the returned array and of the accumulator in which the elements are summed. The dtype of a is used by default unless a has an integer dtype of less precision than the default platform integer. In that case, if a is signed then the platform integer is used while if a is unsigned then an unsigned integer of the same precision as the platform integer is used.
Returns
- NDArray
An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a scalar is returned. If an output array is specified, a reference to out is returned.
Remarks
svd()
public (NDArray, NDArray, NDArray) svd()
Returns
swapaxes(int, int)
Interchange two axes of an array.
public NDArray swapaxes(int axis1, int axis2)
Parameters
Returns
Remarks
tofile(string)
Write array to a file as text or binary (default).
Data is always written in ‘C’ order, independent of the order of a.
The data produced by this method can be recovered using the function fromfile().
public void tofile(string fid)
Parameters
fidstringAn open file object, or a string containing a filename.
Remarks
tolist()
Return the array as an (possibly nested) list.
public object tolist()
Returns
- object
The possibly nested list of array elements.
- For 0-d arrays (scalars): returns the scalar value itself
- For 1-d arrays: returns List<object> of elements
- For n-d arrays: returns nested List<object> structures
Remarks
https://numpy.org/doc/stable/reference/generated/numpy.ndarray.tolist.html
Copy of the array data as a (nested) Python list. Data items are converted to the nearest compatible builtin Python type, via the item function.
If a.ndim is 0, then since the depth of the nested list is 0, it will not be a list at all, but a simple Python scalar.
transpose(int[])
Permute the dimensions of an array.
public NDArray transpose(int[] premute = null)
Parameters
premuteint[]By default, reverse the dimensions, otherwise permute the axes according to the values given.
Returns
- NDArray
a with its axes permuted. A view is returned whenever possible.
Remarks
unique()
public NDArray unique()
Returns
uniqueComplex()
B9: Dedicated unique path for Complex, since System.Numerics.Complex does not implement IComparable<Complex> (prevents reuse of the generic unique<T>). Dedup uses EqualityComparer<Complex>.Default (component-wise value equality, NaN==NaN) then sorts using NumPy lex semantics with NaN at end.
protected NDArray uniqueComplex()
Returns
unique<T>()
protected NDArray unique<T>() where T : unmanaged, IComparable<T>
Returns
Type Parameters
T
var(bool, int?, NPTypeCode?)
Compute the standard deviation along the specified axis. Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
public NDArray var(bool keepdims = false, int? ddof = null, NPTypeCode? dtype = null)
Parameters
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
ddofint?Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
dtypeNPTypeCode?
Returns
- NDArray
returns a new array containing the std values, otherwise a reference to the output array is returned.
Remarks
var(int, bool, int?, NPTypeCode?)
Compute the standard deviation along the specified axis. Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.
public NDArray var(int axis, bool keepdims = false, int? ddof = null, NPTypeCode? dtype = null)
Parameters
axisintAxis or axes along which the standard deviation is computed. The default is to compute the standard deviation of the flattened array.
keepdimsboolIf this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
ddofint?Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
dtypeNPTypeCode?
Returns
- NDArray
returns a new array containing the std values, otherwise a reference to the output array is returned.
Remarks
view(Type)
New view of array with the same data.
public NDArray view(Type dtype = null)
Parameters
dtypeTypeData-type descriptor of the returned view, e.g., float32 or int16. The default, None, results in the view having the same data-type as a. This argument can also be specified as an ndarray sub-class, which then specifies the type of the returned object (this is equivalent to setting the type parameter).
Returns
Remarks
view<T>()
New view of array with the same data.
public NDArray<T> view<T>() where T : unmanaged
Returns
- NDArray<T>
Type Parameters
T
Remarks
vstack(params NDArray[])
Stack arrays in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after 1-D arrays of shape(N,) have been reshaped to(1, N). Rebuilds arrays divided by vsplit.
public NDArray vstack(params NDArray[] tup)
Parameters
tupNDArray[]The arrays must have the same shape along all but the first axis. 1-D arrays must have the same length.
Returns
Operators
operator +(NDArray, NDArray)
public static NDArray operator +(NDArray x, NDArray y)
Parameters
Returns
operator +(NDArray, object)
public static NDArray operator +(NDArray left, object right)
Parameters
Returns
operator +(object, NDArray)
public static NDArray operator +(object left, NDArray right)
Parameters
Returns
operator &(NDArray, NDArray)
Element-wise bitwise AND operation. For boolean arrays: logical AND. For integer arrays: bitwise AND. Supports broadcasting.
public static NDArray operator &(NDArray lhs, NDArray rhs)
Parameters
Returns
operator &(NDArray, object)
Element-wise bitwise AND with any scalar or array-like.
public static NDArray operator &(NDArray lhs, object rhs)
Parameters
Returns
operator &(object, NDArray)
Element-wise bitwise AND with any scalar or array-like on left.
public static NDArray operator &(object lhs, NDArray rhs)
Parameters
Returns
operator |(NDArray, NDArray)
Element-wise bitwise OR operation. For boolean arrays: logical OR. For integer arrays: bitwise OR. Supports broadcasting.
public static NDArray operator |(NDArray lhs, NDArray rhs)
Parameters
Returns
operator |(NDArray, object)
Element-wise bitwise OR with any scalar or array-like.
public static NDArray operator |(NDArray lhs, object rhs)
Parameters
Returns
operator |(object, NDArray)
Element-wise bitwise OR with any scalar or array-like on left.
public static NDArray operator |(object lhs, NDArray rhs)
Parameters
Returns
operator /(NDArray, NDArray)
public static NDArray operator /(NDArray x, NDArray y)
Parameters
Returns
operator /(NDArray, object)
public static NDArray operator /(NDArray left, object right)
Parameters
Returns
operator /(object, NDArray)
public static NDArray operator /(object left, NDArray right)
Parameters
Returns
operator ==(NDArray, NDArray)
Element-wise equal comparison (==). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator ==(NDArray lhs, NDArray rhs)
Parameters
Returns
operator ==(NDArray, object)
Element-wise equal comparison with scalar (==).
public static NDArray<bool> operator ==(NDArray lhs, object rhs)
Parameters
Returns
operator ==(object, NDArray)
Element-wise equal comparison with scalar on left (==).
public static NDArray<bool> operator ==(object lhs, NDArray rhs)
Parameters
Returns
operator ^(NDArray, NDArray)
Element-wise bitwise XOR operation. For boolean arrays: logical XOR. For integer arrays: bitwise XOR. Supports broadcasting.
public static NDArray operator ^(NDArray lhs, NDArray rhs)
Parameters
Returns
operator ^(NDArray, object)
Element-wise bitwise XOR with any scalar or array-like.
public static NDArray operator ^(NDArray lhs, object rhs)
Parameters
Returns
operator ^(object, NDArray)
Element-wise bitwise XOR with any scalar or array-like on left.
public static NDArray operator ^(object lhs, NDArray rhs)
Parameters
Returns
explicit operator Array(NDArray)
public static explicit operator Array(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator bool(NDArray)
public static explicit operator bool(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator byte(NDArray)
public static explicit operator byte(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator char(NDArray)
public static explicit operator char(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator decimal(NDArray)
public static explicit operator decimal(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator double(NDArray)
public static explicit operator double(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator Half(NDArray)
public static explicit operator Half(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator short(NDArray)
public static explicit operator short(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator int(NDArray)
public static explicit operator int(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator long(NDArray)
public static explicit operator long(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator Complex(NDArray)
public static explicit operator Complex(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator sbyte(NDArray)
public static explicit operator sbyte(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator float(NDArray)
public static explicit operator float(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator string(NDArray)
public static explicit operator string(NDArray d)
Parameters
dNDArray
Returns
explicit operator ushort(NDArray)
public static explicit operator ushort(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator uint(NDArray)
public static explicit operator uint(NDArray nd)
Parameters
ndNDArray
Returns
explicit operator ulong(NDArray)
public static explicit operator ulong(NDArray nd)
Parameters
ndNDArray
Returns
operator >(NDArray, NDArray)
Element-wise greater-than comparison (>). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator >(NDArray lhs, NDArray rhs)
Parameters
Returns
operator >(NDArray, object)
Element-wise greater-than comparison with scalar (>).
public static NDArray<bool> operator >(NDArray lhs, object rhs)
Parameters
Returns
operator >(object, NDArray)
Element-wise greater-than comparison with scalar on left (>).
public static NDArray<bool> operator >(object lhs, NDArray rhs)
Parameters
Returns
operator >=(NDArray, NDArray)
Element-wise greater-than-or-equal comparison (>=). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator >=(NDArray lhs, NDArray rhs)
Parameters
Returns
operator >=(NDArray, object)
Element-wise greater-than-or-equal comparison with scalar (>=).
public static NDArray<bool> operator >=(NDArray lhs, object rhs)
Parameters
Returns
operator >=(object, NDArray)
Element-wise greater-than-or-equal comparison with scalar on left (>=).
public static NDArray<bool> operator >=(object lhs, NDArray rhs)
Parameters
Returns
implicit operator NDArray(Array)
public static implicit operator NDArray(Array array)
Parameters
arrayArray
Returns
implicit operator NDArray(bool)
public static implicit operator NDArray(bool d)
Parameters
dbool
Returns
implicit operator NDArray(byte)
public static implicit operator NDArray(byte d)
Parameters
dbyte
Returns
implicit operator NDArray(char)
public static implicit operator NDArray(char d)
Parameters
dchar
Returns
implicit operator NDArray(decimal)
public static implicit operator NDArray(decimal d)
Parameters
ddecimal
Returns
implicit operator NDArray(double)
public static implicit operator NDArray(double d)
Parameters
ddouble
Returns
implicit operator NDArray(Half)
public static implicit operator NDArray(Half d)
Parameters
dHalf
Returns
implicit operator NDArray(short)
public static implicit operator NDArray(short d)
Parameters
dshort
Returns
implicit operator NDArray(int)
public static implicit operator NDArray(int d)
Parameters
dint
Returns
implicit operator NDArray(long)
public static implicit operator NDArray(long d)
Parameters
dlong
Returns
implicit operator NDArray(Complex)
public static implicit operator NDArray(Complex d)
Parameters
dComplex
Returns
implicit operator NDArray(sbyte)
public static implicit operator NDArray(sbyte d)
Parameters
dsbyte
Returns
implicit operator NDArray(float)
public static implicit operator NDArray(float d)
Parameters
dfloat
Returns
implicit operator NDArray(string)
public static implicit operator NDArray(string str)
Parameters
strstring
Returns
implicit operator NDArray(ushort)
public static implicit operator NDArray(ushort d)
Parameters
dushort
Returns
implicit operator NDArray(uint)
public static implicit operator NDArray(uint d)
Parameters
duint
Returns
implicit operator NDArray(ulong)
public static implicit operator NDArray(ulong d)
Parameters
dulong
Returns
operator !=(NDArray, NDArray)
Element-wise not-equal comparison (!=). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator !=(NDArray lhs, NDArray rhs)
Parameters
Returns
operator !=(NDArray, object)
Element-wise not-equal comparison with scalar (!=).
public static NDArray<bool> operator !=(NDArray lhs, object rhs)
Parameters
Returns
operator !=(object, NDArray)
Element-wise not-equal comparison with scalar on left (!=).
public static NDArray<bool> operator !=(object lhs, NDArray rhs)
Parameters
Returns
operator <<(NDArray, NDArray)
Element-wise left shift. Integer dtypes only.
Shifts bits of lhs left by rhs.
Broadcast-aware.
public static NDArray operator <<(NDArray lhs, NDArray rhs)
Parameters
Returns
operator <<(NDArray, object)
Element-wise left shift with any scalar or array-like on RHS. Converts RHS via np.asanyarray(object) (matches NumPy's PyArray_FromAny).
public static NDArray operator <<(NDArray lhs, object rhs)
Parameters
Returns
operator <(NDArray, NDArray)
Element-wise less-than comparison (<). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator <(NDArray lhs, NDArray rhs)
Parameters
Returns
operator <(NDArray, object)
Element-wise less-than comparison with scalar (<).
public static NDArray<bool> operator <(NDArray lhs, object rhs)
Parameters
Returns
operator <(object, NDArray)
Element-wise less-than comparison with scalar on left (<).
public static NDArray<bool> operator <(object lhs, NDArray rhs)
Parameters
Returns
operator <=(NDArray, NDArray)
Element-wise less-than-or-equal comparison (<=). Supports all 12 dtypes and broadcasting.
public static NDArray<bool> operator <=(NDArray lhs, NDArray rhs)
Parameters
Returns
operator <=(NDArray, object)
Element-wise less-than-or-equal comparison with scalar (<=).
public static NDArray<bool> operator <=(NDArray lhs, object rhs)
Parameters
Returns
operator <=(object, NDArray)
Element-wise less-than-or-equal comparison with scalar on left (<=).
public static NDArray<bool> operator <=(object lhs, NDArray rhs)
Parameters
Returns
operator !(NDArray)
public static NDArray<bool> operator !(NDArray self)
Parameters
selfNDArray
Returns
operator %(NDArray, NDArray)
public static NDArray operator %(NDArray x, NDArray y)
Parameters
Returns
operator %(NDArray, object)
public static NDArray operator %(NDArray left, object right)
Parameters
Returns
operator %(object, NDArray)
public static NDArray operator %(object left, NDArray right)
Parameters
Returns
operator *(NDArray, NDArray)
public static NDArray operator *(NDArray x, NDArray y)
Parameters
Returns
operator *(NDArray, object)
public static NDArray operator *(NDArray left, object right)
Parameters
Returns
operator *(object, NDArray)
public static NDArray operator *(object left, NDArray right)
Parameters
Returns
operator ~(NDArray)
Element-wise bitwise NOT (invert) operation. For boolean arrays: logical NOT (~True = False, ~False = True). For integer arrays: bitwise NOT (~0 = -1, ~1 = -2, etc.).
public static NDArray operator ~(NDArray x)
Parameters
xNDArray
Returns
Remarks
Matches NumPy's ~ operator behavior:
- Boolean: ~arr is equivalent to np.logical_not(arr)
- Integer: ~arr is equivalent to np.invert(arr)
operator >>(NDArray, NDArray)
Element-wise right shift. Integer dtypes only.
Shifts bits of lhs right by rhs.
Logical shift for unsigned types, arithmetic shift for signed types.
Broadcast-aware.
public static NDArray operator >>(NDArray lhs, NDArray rhs)
Parameters
Returns
operator >>(NDArray, object)
Element-wise right shift with any scalar or array-like on RHS. Converts RHS via np.asanyarray(object) (matches NumPy's PyArray_FromAny).
public static NDArray operator >>(NDArray lhs, object rhs)
Parameters
Returns
operator -(NDArray, NDArray)
public static NDArray operator -(NDArray x, NDArray y)
Parameters
Returns
operator -(NDArray, object)
public static NDArray operator -(NDArray left, object right)
Parameters
Returns
operator -(object, NDArray)
public static NDArray operator -(object left, NDArray right)
Parameters
Returns
operator -(NDArray)
public static NDArray operator -(NDArray x)
Parameters
xNDArray
Returns
operator +(NDArray)
public static NDArray operator +(NDArray x)
Parameters
xNDArray