BatchedArray¶
redcat.ba.BatchedArray ¶
Bases: BaseBatch[ndarray]
, NDArrayOperatorsMixin
Implement a wrapper around a NumPy array to track the batch axis.
redcat.ba.BatchedArray.add ¶
add(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> Self
Add the input other
, scaled by alpha
, to the self
batch.
Similar to out = self + alpha * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the other value to add to the current batch. |
required |
alpha
|
float
|
Specifies the scale of the batch to add. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the addition of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.add(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[3., 3., 3.],
[3., 3., 3.]], batch_axis=0)
redcat.ba.BatchedArray.add_ ¶
add_(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> None
Add the input other
, scaled by alpha
, to the self
batch.
Similar to self += alpha * other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the other value to add to the current batch. |
required |
alpha
|
float
|
Specifies the scale of the batch to add. |
1
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.add_(ba.full((2, 3), 2.0))
>>> batch
array([[3., 3., 3.],
[3., 3., 3.]], batch_axis=0)
redcat.ba.BatchedArray.argmax ¶
argmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmax()
1
>>> batch.argmax(keepdims=True)
array([[1]])
redcat.ba.BatchedArray.argmax_along_batch ¶
argmax_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmax_along_batch()
array([1, 0, 1])
>>> batch.argmax_along_batch(keepdims=True)
array([[1, 0, 1]])
redcat.ba.BatchedArray.argmin ¶
argmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmin()
0
>>> batch.argmin(keepdims=True)
array([[0]])
redcat.ba.BatchedArray.argmin_along_batch ¶
argmin_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmin_along_batch()
array([0, 1, 0])
>>> batch.argmin_along_batch(keepdims=True)
array([[0, 1, 0]])
redcat.ba.BatchedArray.argsort ¶
argsort(
axis: SupportsIndex | None = -1,
kind: SortKind | None = None,
) -> None
Return the indices that would sort an array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which to sort. |
-1
|
kind
|
SortKind | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> array = batch.argsort()
>>> array
array([[0, 2, 1],
[0, 1, 2]], batch_axis=0)
redcat.ba.BatchedArray.argsort_along_batch ¶
argsort_along_batch(kind: str | None = None) -> None
Return the indices that would sort an array along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str | None
|
Sorting algorithm. The default is |
None
|
Returns:
Type | Description |
---|---|
None
|
The indices that would sort an array along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> array = batch.argsort_along_batch()
>>> array
array([[0, 1, 0],
[1, 0, 1]], batch_axis=0)
redcat.ba.BatchedArray.chunk ¶
chunk(chunks: int, axis: int = 0) -> tuple[Self, ...]
Split an array into the specified number of chunks. Each chunk is a view of the input array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunks
|
int
|
Specifies the number of chunks. |
required |
axis
|
int
|
Specifies the axis along which to split the array. |
0
|
Returns:
Type | Description |
---|---|
tuple[Self, ...]
|
The array split into chunks along the given axis. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the number of chunks is incorrect |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.chunk(chunks=3)
(array([[0, 1], [2, 3]], batch_axis=0),
array([[4, 5], [6, 7]], batch_axis=0),
array([[8, 9]], batch_axis=0))
redcat.ba.BatchedArray.concatenate ¶
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: None = ...,
) -> ndarray
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: int = ...,
) -> Self
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: int | None = 0,
) -> Self | ndarray
Join a sequence of arrays along an existing axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
axis
|
int | None
|
The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. |
0
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The concatenated array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> out = batch.concatenate([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[0, 1, 2],
[4, 5, 6]], batch_axis=0)
>>> out
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_ ¶
concatenate_(
arrays: Iterable[BatchedArray | ndarray], axis: int = 0
) -> None
Join a sequence of arrays along an existing axis in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
axis
|
int
|
The axis along which the arrays will be joined. |
0
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> batch.concatenate_([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_along_batch ¶
concatenate_along_batch(
arrays: Iterable[BatchedArray | ndarray],
) -> Self
Join a sequence of arrays along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
The concatenated array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> out = batch.concatenate_along_batch([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[0, 1, 2],
[4, 5, 6]], batch_axis=0)
>>> out
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_along_batch_ ¶
concatenate_along_batch_(
arrays: Iterable[BatchedArray | ndarray],
) -> None
Join a sequence of arrays along the batch axis in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> batch.concatenate_along_batch_([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.copy ¶
copy(order: OrderACFK = 'C') -> Self
Return a copy of the array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order
|
OrderACFK
|
Controls the memory layout of the copy.
|
'C'
|
Returns:
Type | Description |
---|---|
Self
|
A copy of the array. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> x = array.copy()
>>> x += 1
>>> array
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> x
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.cumprod ¶
cumprod(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
cumprod(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
cumprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative product of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative product of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumprod(axis=0)
array([[ 0, 1],
[ 0, 3],
[ 0, 15],
[ 0, 105],
[ 0, 945]], batch_axis=0)
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.cumprod(axis=1)
array([[ 0, 0, 0, 0, 0],
[ 5, 30, 210, 1680, 15120]], batch_axis=1)
redcat.ba.BatchedArray.cumprod_along_batch ¶
cumprod_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumprod_along_batch()
array([[ 0, 1],
[ 0, 3],
[ 0, 15],
[ 0, 105],
[ 0, 945]], batch_axis=0)
redcat.ba.BatchedArray.cumsum ¶
cumsum(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
cumsum(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
cumsum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative sum of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative sum of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumsum(axis=0)
array([[ 0, 1],
[ 2, 4],
[ 6, 9],
[12, 16],
[20, 25]], batch_axis=0)
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.cumsum(axis=1)
array([[ 0, 1, 3, 6, 10],
[ 5, 11, 18, 26, 35]], batch_axis=1)
redcat.ba.BatchedArray.cumsum_along_batch ¶
cumsum_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumsum_along_batch()
array([[ 0, 1],
[ 2, 4],
[ 6, 9],
[12, 16],
[20, 25]], batch_axis=0)
redcat.ba.BatchedArray.diff ¶
diff(
n: int = 1,
axis: SupportsIndex = -1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> Self | ndarray
Calculate the n-th discrete difference along the given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
axis
|
SupportsIndex
|
The axis along which the difference is taken, default is the last axis. |
-1
|
prepend
|
ArrayLike
|
Values to prepend to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along axis where the
dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> batch.diff(n=1, axis=0)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> batch.diff(axis=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.BatchedArray.diff_along_batch ¶
diff_along_batch(
n: int = 1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> Self | ndarray
Calculate the n-th discrete difference along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
prepend
|
ArrayLike
|
Values to prepend to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along the batch axis where
the dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> batch.diff_along_batch(n=1)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> batch.diff_along_batch(n=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.BatchedArray.empty_like ¶
empty_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array without initializing entries, with the same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
Array of zeros with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.empty_like().shape
(2, 3)
>>> array.empty_like(batch_size=5).shape
(5, 3)
redcat.ba.BatchedArray.floordiv ¶
floordiv(divisor: BatchedArray | ndarray | float) -> Self
Return the largest integer smaller or equal to the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Returns:
Type | Description |
---|---|
Self
|
The largest integer smaller or equal to the division of the inputs. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.floordiv(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.BatchedArray.floordiv_ ¶
floordiv_(divisor: BatchedArray | ndarray | float) -> None
Return the largest integer smaller or equal to the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.floordiv_(ba.full((2, 3), 2.0))
>>> batch
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.BatchedArray.fmod ¶
fmod(divisor: BatchedArray | ndarray | float) -> Self
Compute the element-wise remainder of division.
The current batch is the dividend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the element-wise remainder of division. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.fmod(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.fmod_ ¶
fmod_(divisor: BatchedArray | ndarray | float) -> None
Compute the element-wise remainder of division.
The current batch is the dividend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.fmod_(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.full_like ¶
full_like(
fill_value: float | ArrayLike,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 1
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fill_value
|
float | ArrayLike
|
Specifies the fill value. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.full_like(42.0)
array([[42., 42., 42.],
[42., 42., 42.]], batch_axis=0)
>>> array.full_like(fill_value=42.0, batch_size=5)
array([[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.]], batch_axis=0)
redcat.ba.BatchedArray.index_select ¶
index_select(
index: ndarray | Sequence[int], axis: None = ...
) -> ndarray
index_select(
index: ndarray | Sequence[int], axis: int = ...
) -> Self
index_select(
index: ndarray | Sequence[int], axis: int | None = None
) -> Self | ndarray
Return a new array which indexes the input array along the
given axis using the entries in index
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
ndarray | Sequence[int]
|
The 1-D array containing the indices to index. |
required |
axis
|
int | None
|
The axis over which to select values. By default, the flattened input array is used. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
A new array which indexes the input array along the
given axis using the entries in |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.index_select([2, 4], axis=0)
array([[4, 5],
[8, 9]], batch_axis=0)
>>> batch.index_select(np.array([4, 3, 2, 1, 0]), axis=0)
array([[8, 9],
[6, 7],
[4, 5],
[2, 3],
[0, 1]], batch_axis=0)
redcat.ba.BatchedArray.max ¶
max(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.max()
6
>>> batch.max(axis=0)
array([3, 6, 5])
>>> batch.max(axis=0, keepdims=True)
array([[3, 6, 5]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.max(axis=1)
array([6, 5])
redcat.ba.BatchedArray.max_along_batch ¶
max_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the maximum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.max_along_batch()
array([3, 6, 5])
>>> batch.max_along_batch(keepdims=True)
array([[3, 6, 5]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.max_along_batch()
array([6, 5])
redcat.ba.BatchedArray.mean ¶
mean(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the specified axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.mean()
4.5
>>> batch.mean(axis=0)
array([4., 5.])
>>> batch.mean(axis=0, keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.mean(axis=1)
array([2., 7.])
redcat.ba.BatchedArray.mean_along_batch ¶
mean_along_batch(
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.mean_along_batch()
array([4., 5.])
>>> batch.mean_along_batch(keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.mean_along_batch()
array([2., 7.])
redcat.ba.BatchedArray.median ¶
median(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the median along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the specified axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.median()
4.5
>>> batch.median(axis=0)
array([4., 5.])
>>> batch.median(axis=0, keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.median(axis=1)
array([2., 7.])
redcat.ba.BatchedArray.median_along_batch ¶
median_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> Self | ndarray
Return the median along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the batch axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.median_along_batch()
array([4., 5.])
>>> batch.median_along_batch(keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.median_along_batch()
array([2., 7.])
redcat.ba.BatchedArray.min ¶
min(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.min()
1
>>> batch.min(axis=0)
array([1, 4, 2])
>>> batch.min(axis=0, keepdims=True)
array([[1, 4, 2]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.min(axis=1)
array([1, 3])
redcat.ba.BatchedArray.min_along_batch ¶
min_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the minimum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.min_along_batch()
array([1, 4, 2])
>>> batch.min_along_batch(keepdims=True)
array([[1, 4, 2]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.min_along_batch()
array([1, 3])
redcat.ba.BatchedArray.mul ¶
mul(other: BatchedArray | ndarray | float) -> Self
Multiplies the self
batch by the input `other
.
Similar to out = self * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to multiply. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the multiplication of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.mul(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.mul_ ¶
mul_(other: BatchedArray | ndarray | float) -> None
Multiplies the self
batch by the input `other
.
Similar to self *= other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to multiply. |
required |
Returns:
Type | Description |
---|---|
None
|
A new batch containing the multiplication of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.mul_(ba.full((2, 3), 2.0))
>>> batch
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.nanargmax ¶
nanargmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along an axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along an axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmax()
5
>>> batch.nanargmax(keepdims=True)
array([[5]])
redcat.ba.BatchedArray.nanargmax_along_batch ¶
nanargmax_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmax_along_batch()
array([1, 1, 1])
>>> batch.nanargmax_along_batch(keepdims=True)
array([[1, 1, 1]])
redcat.ba.BatchedArray.nanargmin ¶
nanargmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along an axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along an axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmin()
0
>>> batch.nanargmin(keepdims=True)
array([[0]])
redcat.ba.BatchedArray.nanargmin_along_batch ¶
nanargmin_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmin_along_batch()
array([0, 1, 0])
>>> batch.nanargmin_along_batch(keepdims=True)
array([[0, 1, 0]])
redcat.ba.BatchedArray.nancumprod ¶
nancumprod(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
nancumprod(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
nancumprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative product of elements along a given axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative product of elements along a given axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumprod(axis=0)
array([[ 1., 1., 2.],
[ 3., 4., 10.]], batch_axis=0)
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nancumprod(axis=1)
array([[ 1., 1., 2.],
[ 3., 12., 60.]], batch_axis=1)
redcat.ba.BatchedArray.nancumprod_along_batch ¶
nancumprod_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative product of elements along the batch axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative product of elements along the batch axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumprod_along_batch()
array([[ 1., 1., 2.],
[ 3., 4., 10.]], batch_axis=0)
redcat.ba.BatchedArray.nancumsum ¶
nancumsum(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
nancumsum(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
nancumsum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumsum(axis=0)
array([[1., 0., 2.],
[4., 4., 7.]], batch_axis=0)
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nancumsum(axis=1)
array([[ 1., 1., 3.],
[ 3., 7., 12.]], batch_axis=1)
redcat.ba.BatchedArray.nancumsum_along_batch ¶
nancumsum_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumsum_along_batch()
array([[1., 0., 2.],
[4., 4., 7.]], batch_axis=0)
redcat.ba.BatchedArray.nanmax ¶
nanmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmax()
5.0
>>> batch.nanmax(axis=0)
array([3., 4., 5.])
>>> batch.nanmax(axis=0, keepdims=True)
array([[3., 4., 5.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmax(axis=1)
array([2., 5.])
redcat.ba.BatchedArray.nanmax_along_batch ¶
nanmax_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the maximum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmax_along_batch()
array([3., 4., 5.])
>>> batch.nanmax_along_batch(keepdims=True)
array([[3., 4., 5.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmax_along_batch()
array([2., 5.])
redcat.ba.BatchedArray.nanmean ¶
nanmean(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmean()
3.0
>>> batch.nanmean(axis=0)
array([2. , 4. , 3.5])
>>> batch.nanmean(axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch.nanmean(axis=1)
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmean_along_batch ¶
nanmean_along_batch(
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmean_along_batch()
array([2. , 4. , 3.5])
>>> batch.nanmean_along_batch(keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmean_along_batch()
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmedian ¶
nanmedian(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the median along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmedian()
3.0
>>> batch.nanmedian(axis=0)
array([2. , 4. , 3.5])
>>> batch.nanmedian(axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch.nanmedian(axis=1)
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmedian_along_batch ¶
nanmedian_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> Self | ndarray
Return the median along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmedian_along_batch()
array([2. , 4. , 3.5])
>>> batch.nanmedian_along_batch(keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmedian_along_batch()
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmin ¶
nanmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> batch.nanmin()
2.0
>>> batch.nanmin(axis=0)
array([3., 4., 2.])
>>> batch.nanmin(axis=0, keepdims=True)
array([[3., 4., 2.]])
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmin(axis=1)
array([2., 3.])
redcat.ba.BatchedArray.nanmin_along_batch ¶
nanmin_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the minimum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> batch.nanmin_along_batch()
array([3., 4., 2.])
>>> batch.nanmin_along_batch(keepdims=True)
array([[3., 4., 2.]])
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmin_along_batch()
array([2., 3.])
redcat.ba.BatchedArray.nanprod ¶
nanprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the product of elements along a given axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The product of elements along a given axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanprod(axis=0)
array([ 3., 4., 10.])
>>> batch.nanprod(axis=0, keepdims=True)
array([[ 3., 4., 10.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanprod(axis=1)
array([ 2., 60.])
redcat.ba.BatchedArray.nanprod_along_batch ¶
nanprod_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the product of elements along the batch axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The product of elements along the batch axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanprod_along_batch()
array([ 3., 4., 10.])
redcat.ba.BatchedArray.nansum ¶
nansum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nansum(axis=0)
array([4., 4., 7.])
>>> batch.nansum(axis=0, keepdims=True)
array([[4., 4., 7.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nansum(axis=1)
array([ 3., 12.])
redcat.ba.BatchedArray.nansum_along_batch ¶
nansum_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nansum_along_batch()
array([4., 4., 7.])
redcat.ba.BatchedArray.neg ¶
neg() -> Self
Return a new batch with the negative of the elements.
Returns:
Type | Description |
---|---|
Self
|
A new batch with the negative of the elements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.neg()
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.ones_like ¶
ones_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 1
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.zeros((2, 3))
>>> array.ones_like()
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> array.ones_like(batch_size=5)
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.permute_along_axis ¶
permute_along_axis(
permutation: ndarray | Sequence[int], axis: int
) -> Self
Permute the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permutation
|
ndarray | Sequence[int]
|
Specifies the permutation to use on the data. The dimension of the permutation input should be compatible with the shape of the data. |
required |
axis
|
int
|
Specifies the axis where the permutation is computed. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch with permuted data. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.permute_along_axis([2, 1, 3, 0, 4], axis=0)
array([[4, 5],
[2, 3],
[6, 7],
[0, 1],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.permute_along_axis_ ¶
permute_along_axis_(
permutation: ndarray | Sequence[int], axis: int
) -> None
Permutes the data/batch along a given dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permutation
|
ndarray | Sequence[int]
|
Specifies the permutation to use on the data. The dimension of the permutation input should be compatible with the shape of the data. |
required |
axis
|
int
|
Specifies the axis where the permutation is computed. |
required |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.permute_along_axis_([2, 1, 3, 0, 4], axis=0)
>>> batch
array([[4, 5],
[2, 3],
[6, 7],
[0, 1],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.prod ¶
prod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the product of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The product of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.prod(axis=0)
array([ 3, 24, 10])
>>> batch.prod(axis=0, keepdims=True)
array([[ 3, 24, 10]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.prod(axis=1)
array([12, 60])
redcat.ba.BatchedArray.prod_along_batch ¶
prod_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.prod_along_batch()
array([ 3, 24, 10])
redcat.ba.BatchedArray.select ¶
select(index: int, axis: int) -> ndarray
Select the data along the given axis at the given index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
Specifies the index to select. |
required |
axis
|
int
|
Specifies the index axis. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The batch sliced along the given axis at the given index. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.select(index=2, axis=0)
array([4, 5])
redcat.ba.BatchedArray.shuffle_along_axis ¶
shuffle_along_axis(
axis: int, rng: Generator | None = None
) -> Self
Shuffle the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the shuffle axis. |
required |
rng
|
Generator | None
|
Specifies the pseudorandom number generator. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A new batch with shuffled data along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.shuffle_along_axis(axis=0)
array([[...]], batch_axis=0)
redcat.ba.BatchedArray.shuffle_along_axis_ ¶
shuffle_along_axis_(
axis: int, rng: Generator | None = None
) -> None
Shuffle the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the shuffle axis. |
required |
rng
|
Generator | None
|
Specifies the pseudorandom number generator. |
None
|
Returns:
Type | Description |
---|---|
None
|
A new batch with shuffled data along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.shuffle_along_axis_(axis=0)
>>> batch
array([[...]], batch_axis=0)
redcat.ba.BatchedArray.slice_along_axis ¶
slice_along_axis(
axis: int = 0,
start: int = 0,
stop: int | None = None,
step: int = 1,
) -> Self
Slice the batch in a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the axis along which to slice the array. |
0
|
start
|
int
|
Specifies the index where the slicing starts. |
0
|
stop
|
int | None
|
Specifies the index where the slicing stops.
|
None
|
step
|
int
|
Specifies the increment between each index for slicing. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A slice of the current batch along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.slice_along_axis(start=2)
array([[4, 5],
[6, 7],
[8, 9]], batch_axis=0)
>>> batch.slice_along_axis(stop=3)
array([[0, 1],
[2, 3],
[4, 5]], batch_axis=0)
>>> batch.slice_along_axis(step=2)
array([[0, 1],
[4, 5],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.sort ¶
sort(
axis: SupportsIndex | None = -1,
kind: SortKind | None = None,
) -> None
Sort an array in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which to sort. |
-1
|
kind
|
SortKind | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sort()
>>> batch
array([[1, 2, 6],
[3, 4, 5]], batch_axis=0)
redcat.ba.BatchedArray.sort_along_batch ¶
sort_along_batch(kind: str | None = None) -> None
Sort an array in-place along the batch dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sort_along_batch()
>>> batch
array([[1, 4, 2],
[3, 6, 5]], batch_axis=0)
redcat.ba.BatchedArray.split_along_axis ¶
split_along_axis(
split_size_or_sections: int | Sequence[int],
axis: int = 0,
) -> tuple[Self, ...]
Split the batch into chunks along a given axis.
Notes
This function has a slightly different behavior as
numpy.split
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split_size_or_sections
|
int | Sequence[int]
|
Specifies the size of a single chunk or list of sizes for each chunk. |
required |
axis
|
int
|
Specifies the axis along which to split the array. |
0
|
Returns:
Type | Description |
---|---|
tuple[Self, ...]
|
The batch split into chunks along the given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.split_along_axis(2, axis=0)
(array([[0, 1], [2, 3]], batch_axis=0),
array([[4, 5], [6, 7]], batch_axis=0),
array([[8, 9]], batch_axis=0))
redcat.ba.BatchedArray.sub ¶
sub(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> Self
Subtracts the input other
, scaled by alpha
, to the
self
batch.
Similar to out = self - alpha * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to subtract. |
required |
alpha
|
float
|
Specifies the scale of the batch to substract. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the diffence of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.sub(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.sub_ ¶
sub_(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> None
Subtracts the input other
, scaled by alpha
, to the
self
batch.
Similar to self -= alpha * other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to subtract. |
required |
alpha
|
float
|
Specifies the scale of the batch to substract. |
1
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.sub_(ba.full((2, 3), 2.0))
>>> batch
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.sum ¶
sum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the sum of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The sum of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sum(axis=0)
array([ 4, 10, 7])
>>> batch.sum(axis=0, keepdims=True)
array([[ 4, 10, 7]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.sum(axis=1)
array([ 9, 12])
redcat.ba.BatchedArray.sum_along_batch ¶
sum_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sum_along_batch()
array([ 4, 10, 7])
redcat.ba.BatchedArray.truediv ¶
truediv(divisor: BatchedArray | ndarray | float) -> Self
Return the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Returns:
Type | Description |
---|---|
Self
|
The division of the inputs. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.truediv(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5]], batch_axis=0)
redcat.ba.BatchedArray.truediv_ ¶
truediv_(divisor: BatchedArray | ndarray | float) -> None
Return the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.truediv_(ba.full((2, 3), 2.0))
>>> batch
array([[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5]], batch_axis=0)
redcat.ba.BatchedArray.zeros_like ¶
zeros_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 0
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.zeros_like()
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
>>> array.zeros_like(batch_size=5)
array([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba ¶
Contain the implementation of BatchedArray
and its associated
functions.
BatchedArray
is a custom NumPy array container to make batch
manipulation easier.
redcat.ba.BatchedArray ¶
Bases: BaseBatch[ndarray]
, NDArrayOperatorsMixin
Implement a wrapper around a NumPy array to track the batch axis.
redcat.ba.BatchedArray.add ¶
add(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> Self
Add the input other
, scaled by alpha
, to the self
batch.
Similar to out = self + alpha * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the other value to add to the current batch. |
required |
alpha
|
float
|
Specifies the scale of the batch to add. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the addition of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.add(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[3., 3., 3.],
[3., 3., 3.]], batch_axis=0)
redcat.ba.BatchedArray.add_ ¶
add_(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> None
Add the input other
, scaled by alpha
, to the self
batch.
Similar to self += alpha * other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the other value to add to the current batch. |
required |
alpha
|
float
|
Specifies the scale of the batch to add. |
1
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.add_(ba.full((2, 3), 2.0))
>>> batch
array([[3., 3., 3.],
[3., 3., 3.]], batch_axis=0)
redcat.ba.BatchedArray.argmax ¶
argmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmax()
1
>>> batch.argmax(keepdims=True)
array([[1]])
redcat.ba.BatchedArray.argmax_along_batch ¶
argmax_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmax_along_batch()
array([1, 0, 1])
>>> batch.argmax_along_batch(keepdims=True)
array([[1, 0, 1]])
redcat.ba.BatchedArray.argmin ¶
argmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmin()
0
>>> batch.argmin(keepdims=True)
array([[0]])
redcat.ba.BatchedArray.argmin_along_batch ¶
argmin_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.argmin_along_batch()
array([0, 1, 0])
>>> batch.argmin_along_batch(keepdims=True)
array([[0, 1, 0]])
redcat.ba.BatchedArray.argsort ¶
argsort(
axis: SupportsIndex | None = -1,
kind: SortKind | None = None,
) -> None
Return the indices that would sort an array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which to sort. |
-1
|
kind
|
SortKind | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> array = batch.argsort()
>>> array
array([[0, 2, 1],
[0, 1, 2]], batch_axis=0)
redcat.ba.BatchedArray.argsort_along_batch ¶
argsort_along_batch(kind: str | None = None) -> None
Return the indices that would sort an array along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str | None
|
Sorting algorithm. The default is |
None
|
Returns:
Type | Description |
---|---|
None
|
The indices that would sort an array along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> array = batch.argsort_along_batch()
>>> array
array([[0, 1, 0],
[1, 0, 1]], batch_axis=0)
redcat.ba.BatchedArray.chunk ¶
chunk(chunks: int, axis: int = 0) -> tuple[Self, ...]
Split an array into the specified number of chunks. Each chunk is a view of the input array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunks
|
int
|
Specifies the number of chunks. |
required |
axis
|
int
|
Specifies the axis along which to split the array. |
0
|
Returns:
Type | Description |
---|---|
tuple[Self, ...]
|
The array split into chunks along the given axis. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the number of chunks is incorrect |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.chunk(chunks=3)
(array([[0, 1], [2, 3]], batch_axis=0),
array([[4, 5], [6, 7]], batch_axis=0),
array([[8, 9]], batch_axis=0))
redcat.ba.BatchedArray.concatenate ¶
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: None = ...,
) -> ndarray
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: int = ...,
) -> Self
concatenate(
arrays: Iterable[BatchedArray | ndarray],
axis: int | None = 0,
) -> Self | ndarray
Join a sequence of arrays along an existing axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
axis
|
int | None
|
The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. |
0
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The concatenated array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> out = batch.concatenate([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[0, 1, 2],
[4, 5, 6]], batch_axis=0)
>>> out
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_ ¶
concatenate_(
arrays: Iterable[BatchedArray | ndarray], axis: int = 0
) -> None
Join a sequence of arrays along an existing axis in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
axis
|
int
|
The axis along which the arrays will be joined. |
0
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> batch.concatenate_([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_along_batch ¶
concatenate_along_batch(
arrays: Iterable[BatchedArray | ndarray],
) -> Self
Join a sequence of arrays along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
Returns:
Type | Description |
---|---|
Self
|
The concatenated array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> out = batch.concatenate_along_batch([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[0, 1, 2],
[4, 5, 6]], batch_axis=0)
>>> out
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.concatenate_along_batch_ ¶
concatenate_along_batch_(
arrays: Iterable[BatchedArray | ndarray],
) -> None
Join a sequence of arrays along the batch axis in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Iterable[BatchedArray | ndarray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.array([[0, 1, 2], [4, 5, 6]])
>>> batch.concatenate_along_batch_([ba.array([[10, 11, 12], [13, 14, 15]])])
>>> batch
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.BatchedArray.copy ¶
copy(order: OrderACFK = 'C') -> Self
Return a copy of the array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order
|
OrderACFK
|
Controls the memory layout of the copy.
|
'C'
|
Returns:
Type | Description |
---|---|
Self
|
A copy of the array. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> x = array.copy()
>>> x += 1
>>> array
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> x
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.cumprod ¶
cumprod(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
cumprod(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
cumprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative product of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative product of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumprod(axis=0)
array([[ 0, 1],
[ 0, 3],
[ 0, 15],
[ 0, 105],
[ 0, 945]], batch_axis=0)
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.cumprod(axis=1)
array([[ 0, 0, 0, 0, 0],
[ 5, 30, 210, 1680, 15120]], batch_axis=1)
redcat.ba.BatchedArray.cumprod_along_batch ¶
cumprod_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumprod_along_batch()
array([[ 0, 1],
[ 0, 3],
[ 0, 15],
[ 0, 105],
[ 0, 945]], batch_axis=0)
redcat.ba.BatchedArray.cumsum ¶
cumsum(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
cumsum(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
cumsum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative sum of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative sum of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumsum(axis=0)
array([[ 0, 1],
[ 2, 4],
[ 6, 9],
[12, 16],
[20, 25]], batch_axis=0)
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.cumsum(axis=1)
array([[ 0, 1, 3, 6, 10],
[ 5, 11, 18, 26, 35]], batch_axis=1)
redcat.ba.BatchedArray.cumsum_along_batch ¶
cumsum_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.cumsum_along_batch()
array([[ 0, 1],
[ 2, 4],
[ 6, 9],
[12, 16],
[20, 25]], batch_axis=0)
redcat.ba.BatchedArray.diff ¶
diff(
n: int = 1,
axis: SupportsIndex = -1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> Self | ndarray
Calculate the n-th discrete difference along the given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
axis
|
SupportsIndex
|
The axis along which the difference is taken, default is the last axis. |
-1
|
prepend
|
ArrayLike
|
Values to prepend to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along axis where the
dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> batch.diff(n=1, axis=0)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> batch.diff(axis=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.BatchedArray.diff_along_batch ¶
diff_along_batch(
n: int = 1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> Self | ndarray
Calculate the n-th discrete difference along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
prepend
|
ArrayLike
|
Values to prepend to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along the batch axis where
the dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> batch.diff_along_batch(n=1)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> batch.diff_along_batch(n=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.BatchedArray.empty_like ¶
empty_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array without initializing entries, with the same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
Array of zeros with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.empty_like().shape
(2, 3)
>>> array.empty_like(batch_size=5).shape
(5, 3)
redcat.ba.BatchedArray.floordiv ¶
floordiv(divisor: BatchedArray | ndarray | float) -> Self
Return the largest integer smaller or equal to the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Returns:
Type | Description |
---|---|
Self
|
The largest integer smaller or equal to the division of the inputs. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.floordiv(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.BatchedArray.floordiv_ ¶
floordiv_(divisor: BatchedArray | ndarray | float) -> None
Return the largest integer smaller or equal to the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.floordiv_(ba.full((2, 3), 2.0))
>>> batch
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.BatchedArray.fmod ¶
fmod(divisor: BatchedArray | ndarray | float) -> Self
Compute the element-wise remainder of division.
The current batch is the dividend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the element-wise remainder of division. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.fmod(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.fmod_ ¶
fmod_(divisor: BatchedArray | ndarray | float) -> None
Compute the element-wise remainder of division.
The current batch is the dividend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.fmod_(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.full_like ¶
full_like(
fill_value: float | ArrayLike,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 1
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fill_value
|
float | ArrayLike
|
Specifies the fill value. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.full_like(42.0)
array([[42., 42., 42.],
[42., 42., 42.]], batch_axis=0)
>>> array.full_like(fill_value=42.0, batch_size=5)
array([[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.],
[42., 42., 42.]], batch_axis=0)
redcat.ba.BatchedArray.index_select ¶
index_select(
index: ndarray | Sequence[int], axis: None = ...
) -> ndarray
index_select(
index: ndarray | Sequence[int], axis: int = ...
) -> Self
index_select(
index: ndarray | Sequence[int], axis: int | None = None
) -> Self | ndarray
Return a new array which indexes the input array along the
given axis using the entries in index
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
ndarray | Sequence[int]
|
The 1-D array containing the indices to index. |
required |
axis
|
int | None
|
The axis over which to select values. By default, the flattened input array is used. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
A new array which indexes the input array along the
given axis using the entries in |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.index_select([2, 4], axis=0)
array([[4, 5],
[8, 9]], batch_axis=0)
>>> batch.index_select(np.array([4, 3, 2, 1, 0]), axis=0)
array([[8, 9],
[6, 7],
[4, 5],
[2, 3],
[0, 1]], batch_axis=0)
redcat.ba.BatchedArray.max ¶
max(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.max()
6
>>> batch.max(axis=0)
array([3, 6, 5])
>>> batch.max(axis=0, keepdims=True)
array([[3, 6, 5]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.max(axis=1)
array([6, 5])
redcat.ba.BatchedArray.max_along_batch ¶
max_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the maximum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.max_along_batch()
array([3, 6, 5])
>>> batch.max_along_batch(keepdims=True)
array([[3, 6, 5]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.max_along_batch()
array([6, 5])
redcat.ba.BatchedArray.mean ¶
mean(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the specified axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.mean()
4.5
>>> batch.mean(axis=0)
array([4., 5.])
>>> batch.mean(axis=0, keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.mean(axis=1)
array([2., 7.])
redcat.ba.BatchedArray.mean_along_batch ¶
mean_along_batch(
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.mean_along_batch()
array([4., 5.])
>>> batch.mean_along_batch(keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.mean_along_batch()
array([2., 7.])
redcat.ba.BatchedArray.median ¶
median(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the median along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the specified axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.median()
4.5
>>> batch.median(axis=0)
array([4., 5.])
>>> batch.median(axis=0, keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.median(axis=1)
array([2., 7.])
redcat.ba.BatchedArray.median_along_batch ¶
median_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> Self | ndarray
Return the median along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the batch axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.median_along_batch()
array([4., 5.])
>>> batch.median_along_batch(keepdims=True)
array([[4., 5.]])
>>> batch = BatchedArray(np.arange(10).reshape(2, 5), batch_axis=1)
>>> batch.median_along_batch()
array([2., 7.])
redcat.ba.BatchedArray.min ¶
min(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.min()
1
>>> batch.min(axis=0)
array([1, 4, 2])
>>> batch.min(axis=0, keepdims=True)
array([[1, 4, 2]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.min(axis=1)
array([1, 3])
redcat.ba.BatchedArray.min_along_batch ¶
min_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the minimum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.min_along_batch()
array([1, 4, 2])
>>> batch.min_along_batch(keepdims=True)
array([[1, 4, 2]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.min_along_batch()
array([1, 3])
redcat.ba.BatchedArray.mul ¶
mul(other: BatchedArray | ndarray | float) -> Self
Multiplies the self
batch by the input `other
.
Similar to out = self * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to multiply. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the multiplication of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.mul(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.mul_ ¶
mul_(other: BatchedArray | ndarray | float) -> None
Multiplies the self
batch by the input `other
.
Similar to self *= other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to multiply. |
required |
Returns:
Type | Description |
---|---|
None
|
A new batch containing the multiplication of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.mul_(ba.full((2, 3), 2.0))
>>> batch
array([[2., 2., 2.],
[2., 2., 2.]], batch_axis=0)
redcat.ba.BatchedArray.nanargmax ¶
nanargmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along an axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along an axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmax()
5
>>> batch.nanargmax(keepdims=True)
array([[5]])
redcat.ba.BatchedArray.nanargmax_along_batch ¶
nanargmax_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmax_along_batch()
array([1, 1, 1])
>>> batch.nanargmax_along_batch(keepdims=True)
array([[1, 1, 1]])
redcat.ba.BatchedArray.nanargmin ¶
nanargmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along an axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
By default, the index is into the flattened array, otherwise along the specified axis. |
None
|
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along an axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmin()
0
>>> batch.nanargmin(keepdims=True)
array([[0]])
redcat.ba.BatchedArray.nanargmin_along_batch ¶
nanargmin_along_batch(
out: ndarray | None = None, *, keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
By default, the index is into the flattened array, otherwise along the specified axis. |
required | |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanargmin_along_batch()
array([0, 1, 0])
>>> batch.nanargmin_along_batch(keepdims=True)
array([[0, 1, 0]])
redcat.ba.BatchedArray.nancumprod ¶
nancumprod(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
nancumprod(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
nancumprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative product of elements along a given axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative product of elements along a given axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumprod(axis=0)
array([[ 1., 1., 2.],
[ 3., 4., 10.]], batch_axis=0)
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nancumprod(axis=1)
array([[ 1., 1., 2.],
[ 3., 12., 60.]], batch_axis=1)
redcat.ba.BatchedArray.nancumprod_along_batch ¶
nancumprod_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative product of elements along the batch axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative product of elements along the batch axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumprod_along_batch()
array([[ 1., 1., 2.],
[ 3., 4., 10.]], batch_axis=0)
redcat.ba.BatchedArray.nancumsum ¶
nancumsum(
axis: None = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> ndarray
nancumsum(
axis: SupportsIndex = ...,
dtype: DTypeLike = ...,
out: ndarray | None = ...,
) -> Self
nancumsum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> Self | ndarray
Return the cumulative sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The cumulative sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumsum(axis=0)
array([[1., 0., 2.],
[4., 4., 7.]], batch_axis=0)
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nancumsum(axis=1)
array([[ 1., 1., 3.],
[ 3., 7., 12.]], batch_axis=1)
redcat.ba.BatchedArray.nancumsum_along_batch ¶
nancumsum_along_batch(dtype: DTypeLike = None) -> Self
Return the cumulative sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
Self
|
The cumulative sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nancumsum_along_batch()
array([[1., 0., 2.],
[4., 4., 7.]], batch_axis=0)
redcat.ba.BatchedArray.nanmax ¶
nanmax(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmax()
5.0
>>> batch.nanmax(axis=0)
array([3., 4., 5.])
>>> batch.nanmax(axis=0, keepdims=True)
array([[3., 4., 5.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmax(axis=1)
array([2., 5.])
redcat.ba.BatchedArray.nanmax_along_batch ¶
nanmax_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the maximum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmax_along_batch()
array([3., 4., 5.])
>>> batch.nanmax_along_batch(keepdims=True)
array([[3., 4., 5.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmax_along_batch()
array([2., 5.])
redcat.ba.BatchedArray.nanmean ¶
nanmean(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmean()
3.0
>>> batch.nanmean(axis=0)
array([2. , 4. , 3.5])
>>> batch.nanmean(axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch.nanmean(axis=1)
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmean_along_batch ¶
nanmean_along_batch(
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the arithmetic mean along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The arithmetic mean along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmean_along_batch()
array([2. , 4. , 3.5])
>>> batch.nanmean_along_batch(keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmean_along_batch()
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmedian ¶
nanmedian(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the median along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative sum is computed. By default, the input is flattened. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmedian()
3.0
>>> batch.nanmedian(axis=0)
array([2. , 4. , 3.5])
>>> batch.nanmedian(axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch.nanmedian(axis=1)
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmedian_along_batch ¶
nanmedian_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> Self | ndarray
Return the median along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The median along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanmedian_along_batch()
array([2. , 4. , 3.5])
>>> batch.nanmedian_along_batch(keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmedian_along_batch()
array([1.5, 4. ])
redcat.ba.BatchedArray.nanmin ¶
nanmin(
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> batch.nanmin()
2.0
>>> batch.nanmin(axis=0)
array([3., 4., 2.])
>>> batch.nanmin(axis=0, keepdims=True)
array([[3., 4., 2.]])
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmin(axis=1)
array([2., 3.])
redcat.ba.BatchedArray.nanmin_along_batch ¶
nanmin_along_batch(
out: ndarray | None = None, keepdims: bool = False
) -> ndarray
Return the minimum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> batch.nanmin_along_batch()
array([3., 4., 2.])
>>> batch.nanmin_along_batch(keepdims=True)
array([[3., 4., 2.]])
>>> batch = BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanmin_along_batch()
array([2., 3.])
redcat.ba.BatchedArray.nanprod ¶
nanprod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the product of elements along a given axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The product of elements along a given axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanprod(axis=0)
array([ 3., 4., 10.])
>>> batch.nanprod(axis=0, keepdims=True)
array([[ 3., 4., 10.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nanprod(axis=1)
array([ 2., 60.])
redcat.ba.BatchedArray.nanprod_along_batch ¶
nanprod_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the product of elements along the batch axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The product of elements along the batch axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nanprod_along_batch()
array([ 3., 4., 10.])
redcat.ba.BatchedArray.nansum ¶
nansum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nansum(axis=0)
array([4., 4., 7.])
>>> batch.nansum(axis=0, keepdims=True)
array([[4., 4., 7.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.nansum(axis=1)
array([ 3., 12.])
redcat.ba.BatchedArray.nansum_along_batch ¶
nansum_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> batch.nansum_along_batch()
array([4., 4., 7.])
redcat.ba.BatchedArray.neg ¶
neg() -> Self
Return a new batch with the negative of the elements.
Returns:
Type | Description |
---|---|
Self
|
A new batch with the negative of the elements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.neg()
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.ones_like ¶
ones_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 1
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.zeros((2, 3))
>>> array.ones_like()
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> array.ones_like(batch_size=5)
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.BatchedArray.permute_along_axis ¶
permute_along_axis(
permutation: ndarray | Sequence[int], axis: int
) -> Self
Permute the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permutation
|
ndarray | Sequence[int]
|
Specifies the permutation to use on the data. The dimension of the permutation input should be compatible with the shape of the data. |
required |
axis
|
int
|
Specifies the axis where the permutation is computed. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new batch with permuted data. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.permute_along_axis([2, 1, 3, 0, 4], axis=0)
array([[4, 5],
[2, 3],
[6, 7],
[0, 1],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.permute_along_axis_ ¶
permute_along_axis_(
permutation: ndarray | Sequence[int], axis: int
) -> None
Permutes the data/batch along a given dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permutation
|
ndarray | Sequence[int]
|
Specifies the permutation to use on the data. The dimension of the permutation input should be compatible with the shape of the data. |
required |
axis
|
int
|
Specifies the axis where the permutation is computed. |
required |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.permute_along_axis_([2, 1, 3, 0, 4], axis=0)
>>> batch
array([[4, 5],
[2, 3],
[6, 7],
[0, 1],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.prod ¶
prod(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the product of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The product of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.prod(axis=0)
array([ 3, 24, 10])
>>> batch.prod(axis=0, keepdims=True)
array([[ 3, 24, 10]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.prod(axis=1)
array([12, 60])
redcat.ba.BatchedArray.prod_along_batch ¶
prod_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.prod_along_batch()
array([ 3, 24, 10])
redcat.ba.BatchedArray.select ¶
select(index: int, axis: int) -> ndarray
Select the data along the given axis at the given index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
Specifies the index to select. |
required |
axis
|
int
|
Specifies the index axis. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The batch sliced along the given axis at the given index. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.select(index=2, axis=0)
array([4, 5])
redcat.ba.BatchedArray.shuffle_along_axis ¶
shuffle_along_axis(
axis: int, rng: Generator | None = None
) -> Self
Shuffle the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the shuffle axis. |
required |
rng
|
Generator | None
|
Specifies the pseudorandom number generator. |
None
|
Returns:
Type | Description |
---|---|
Self
|
A new batch with shuffled data along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.shuffle_along_axis(axis=0)
array([[...]], batch_axis=0)
redcat.ba.BatchedArray.shuffle_along_axis_ ¶
shuffle_along_axis_(
axis: int, rng: Generator | None = None
) -> None
Shuffle the data/batch along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the shuffle axis. |
required |
rng
|
Generator | None
|
Specifies the pseudorandom number generator. |
None
|
Returns:
Type | Description |
---|---|
None
|
A new batch with shuffled data along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.shuffle_along_axis_(axis=0)
>>> batch
array([[...]], batch_axis=0)
redcat.ba.BatchedArray.slice_along_axis ¶
slice_along_axis(
axis: int = 0,
start: int = 0,
stop: int | None = None,
step: int = 1,
) -> Self
Slice the batch in a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
int
|
Specifies the axis along which to slice the array. |
0
|
start
|
int
|
Specifies the index where the slicing starts. |
0
|
stop
|
int | None
|
Specifies the index where the slicing stops.
|
None
|
step
|
int
|
Specifies the increment between each index for slicing. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A slice of the current batch along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.slice_along_axis(start=2)
array([[4, 5],
[6, 7],
[8, 9]], batch_axis=0)
>>> batch.slice_along_axis(stop=3)
array([[0, 1],
[2, 3],
[4, 5]], batch_axis=0)
>>> batch.slice_along_axis(step=2)
array([[0, 1],
[4, 5],
[8, 9]], batch_axis=0)
redcat.ba.BatchedArray.sort ¶
sort(
axis: SupportsIndex | None = -1,
kind: SortKind | None = None,
) -> None
Sort an array in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which to sort. |
-1
|
kind
|
SortKind | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sort()
>>> batch
array([[1, 2, 6],
[3, 4, 5]], batch_axis=0)
redcat.ba.BatchedArray.sort_along_batch ¶
sort_along_batch(kind: str | None = None) -> None
Sort an array in-place along the batch dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str | None
|
Sorting algorithm. The default is |
None
|
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sort_along_batch()
>>> batch
array([[1, 4, 2],
[3, 6, 5]], batch_axis=0)
redcat.ba.BatchedArray.split_along_axis ¶
split_along_axis(
split_size_or_sections: int | Sequence[int],
axis: int = 0,
) -> tuple[Self, ...]
Split the batch into chunks along a given axis.
Notes
This function has a slightly different behavior as
numpy.split
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
split_size_or_sections
|
int | Sequence[int]
|
Specifies the size of a single chunk or list of sizes for each chunk. |
required |
axis
|
int
|
Specifies the axis along which to split the array. |
0
|
Returns:
Type | Description |
---|---|
tuple[Self, ...]
|
The batch split into chunks along the given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.arange(10).reshape(5, 2))
>>> batch.split_along_axis(2, axis=0)
(array([[0, 1], [2, 3]], batch_axis=0),
array([[4, 5], [6, 7]], batch_axis=0),
array([[8, 9]], batch_axis=0))
redcat.ba.BatchedArray.sub ¶
sub(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> Self
Subtracts the input other
, scaled by alpha
, to the
self
batch.
Similar to out = self - alpha * other
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to subtract. |
required |
alpha
|
float
|
Specifies the scale of the batch to substract. |
1
|
Returns:
Type | Description |
---|---|
Self
|
A new batch containing the diffence of the two batches. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.sub(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.sub_ ¶
sub_(
other: BatchedArray | ndarray | float, alpha: float = 1
) -> None
Subtracts the input other
, scaled by alpha
, to the
self
batch.
Similar to self -= alpha * other
(in-place)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
BatchedArray | ndarray | float
|
Specifies the value to subtract. |
required |
alpha
|
float
|
Specifies the scale of the batch to substract. |
1
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.sub_(ba.full((2, 3), 2.0))
>>> batch
array([[-1., -1., -1.],
[-1., -1., -1.]], batch_axis=0)
redcat.ba.BatchedArray.sum ¶
sum(
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> Self | ndarray
Return the sum of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self | ndarray
|
The sum of elements along a given axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sum(axis=0)
array([ 4, 10, 7])
>>> batch.sum(axis=0, keepdims=True)
array([[ 4, 10, 7]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> batch.sum(axis=1)
array([ 9, 12])
redcat.ba.BatchedArray.sum_along_batch ¶
sum_along_batch(
dtype: DTypeLike = None, keepdims: bool = False
) -> Self
Return the sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
Self
|
The sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import BatchedArray
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> batch.sum_along_batch()
array([ 4, 10, 7])
redcat.ba.BatchedArray.truediv ¶
truediv(divisor: BatchedArray | ndarray | float) -> Self
Return the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Returns:
Type | Description |
---|---|
Self
|
The division of the inputs. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> out = batch.truediv(ba.full((2, 3), 2.0))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
>>> out
array([[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5]], batch_axis=0)
redcat.ba.BatchedArray.truediv_ ¶
truediv_(divisor: BatchedArray | ndarray | float) -> None
Return the division of the inputs.
The current batch is the dividend/numerator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
divisor
|
BatchedArray | ndarray | float
|
Specifies the divisor/denominator. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch.truediv_(ba.full((2, 3), 2.0))
>>> batch
array([[0.5, 0.5, 0.5],
[0.5, 0.5, 0.5]], batch_axis=0)
redcat.ba.BatchedArray.zeros_like ¶
zeros_like(
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> Self
Return an array filled with the scalar value 0
, with the
same shape as the current array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order= |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
Self
|
An array filled with the scalar value |
Example usage:
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> array.zeros_like()
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
>>> array.zeros_like(batch_size=5)
array([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.argmax ¶
argmax(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
See numpy.argmax
documentation.
redcat.ba.argmax_along_batch ¶
argmax_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.argmax_along_batch(batch)
array([1, 0, 1])
>>> ba.argmax_along_batch(batch, keepdims=True)
array([[1, 0, 1]])
redcat.ba.argmin ¶
argmin(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
See numpy.argmin
documentation.
redcat.ba.argmin_along_batch ¶
argmin_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.argmin_along_batch(batch)
array([0, 1, 0])
>>> ba.argmin_along_batch(batch, keepdims=True)
array([[0, 1, 0]])
redcat.ba.argsort ¶
argsort(
a: TBatchedArray,
axis: SupportsIndex | None = -1,
kind: SortKind | None = None,
) -> TBatchedArray
See numpy.argsort
documentation.
redcat.ba.argsort_along_batch ¶
argsort_along_batch(
a: TBatchedArray, kind: SortKind | None = None
) -> TBatchedArray
Return the indices that would sort an array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
kind
|
SortKind | None
|
Sorting algorithm. The default is 'quicksort'. Note that both 'stable' and 'mergesort' use timsort under the covers and, in general, the actual implementation will vary with datatype. The 'mergesort' option is retained for backwards compatibility. |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The indices that would sort an array. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.argsort_along_batch(batch)
array([[0, 1, 0],
[1, 0, 1]], batch_axis=0)
redcat.ba.array ¶
array(
data: ArrayLike | Sequence,
dtype: DTypeLike = None,
*,
batch_axis: int = 0,
**kwargs: Any
) -> BatchedArray
Create an array.
Equivalent of numpy.array
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ArrayLike | Sequence
|
An array, any object exposing the array interface,
an object whose |
required |
dtype
|
DTypeLike
|
The desired data-type for the array. If not given, NumPy will try to use a default dtype that can represent the values (by applying promotion rules when necessary.) |
None
|
batch_axis
|
int
|
Specifies the batch axis in the array object. |
0
|
**kwargs
|
Any
|
See the documentation of |
{}
|
Returns:
Type | Description |
---|---|
BatchedArray
|
An array object satisfying the specified requirements. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.array(np.arange(10).reshape(2, 5))
>>> batch
array([[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]], batch_axis=0)
redcat.ba.check_data_and_axis ¶
check_data_and_axis(data: ndarray, batch_axis: int) -> None
Check if the array data
and batch_axis
are correct.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
Specifies the array in the batch. |
required |
batch_axis
|
int
|
Specifies the batch axis in the array object. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if one of the input is incorrect. |
Example usage:
>>> import numpy as np
>>> from redcat.ba import check_data_and_axis
>>> check_data_and_axis(np.ones((2, 3)), batch_axis=0)
redcat.ba.check_same_batch_axis ¶
check_same_batch_axis(axes: set[int]) -> None
Check the batch axes are the same.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axes
|
set[int]
|
Specifies the batch axes to check. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if there are more than one batch axis. |
Example usage:
>>> from redcat.ba import check_same_batch_axis
>>> check_same_batch_axis({0})
redcat.ba.concatenate ¶
concatenate(
arrays: Sequence[TBatchedArray], axis: int | None = 0
) -> TBatchedArray | ndarray
See numpy.concatenate
documentation.
redcat.ba.concatenate_along_batch ¶
concatenate_along_batch(
arrays: Sequence[TBatchedArray],
) -> TBatchedArray | ndarray
Join a sequence of arrays along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arrays
|
Sequence[TBatchedArray]
|
The arrays must have the same shape, except in the dimension corresponding to axis. |
required |
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The concatenated array. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the batch axes are different. |
Example usage:
>>> from redcat import ba
>>> arrays = [
... ba.array([[0, 1, 2], [4, 5, 6]]),
... ba.array([[10, 11, 12], [13, 14, 15]]),
... ]
>>> out = ba.concatenate_along_batch(arrays)
>>> out
array([[ 0, 1, 2],
[ 4, 5, 6],
[10, 11, 12],
[13, 14, 15]], batch_axis=0)
redcat.ba.cumprod ¶
cumprod(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> TBatchedArray | ndarray
See numpy.cumprod
documentation.
redcat.ba.cumprod_along_batch ¶
cumprod_along_batch(
a: TBatchedArray, dtype: DTypeLike = None
) -> TBatchedArray
Return the cumulative product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The cumulative product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.arange(10).reshape(5, 2))
>>> ba.cumprod_along_batch(batch)
array([[ 0, 1],
[ 0, 3],
[ 0, 15],
[ 0, 105],
[ 0, 945]], batch_axis=0)
redcat.ba.cumsum ¶
cumsum(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> TBatchedArray | ndarray
See numpy.cumsum
documentation.
redcat.ba.cumsum_along_batch ¶
cumsum_along_batch(
a: TBatchedArray, dtype: DTypeLike = None
) -> TBatchedArray
Return the cumulative sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The cumulative sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.arange(10).reshape(5, 2))
>>> ba.cumsum_along_batch(batch)
array([[ 0, 1],
[ 2, 4],
[ 6, 9],
[12, 16],
[20, 25]], batch_axis=0)
redcat.ba.diff ¶
diff(
a: TBatchedArray,
n: int = 1,
axis: SupportsIndex = -1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> TBatchedArray | ndarray
Calculate the n-th discrete difference along the given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
axis
|
SupportsIndex
|
The axis along which the difference is taken, default is the last axis. |
-1
|
prepend
|
ArrayLike
|
Values to prepend to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the current array along axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along axis where the
dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> ba.diff(batch, n=1, axis=0)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> ba.diff(batch, axis=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.diff_along_batch ¶
diff_along_batch(
a: TBatchedArray,
n: int = 1,
prepend: ArrayLike = _NoValue,
append: ArrayLike = _NoValue,
) -> TBatchedArray | ndarray
Calculate the n-th discrete difference along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
n
|
int
|
The number of times values are differenced. If zero, the input is returned as-is. |
1
|
prepend
|
ArrayLike
|
Values to prepend to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
append
|
ArrayLike
|
Values to append to the array along the batch axis prior to performing the difference. Scalar values are expanded to arrays with length 1 in the direction of axis and the shape of the input array in along all other axes. Otherwise the dimension and shape must match the current array except along axis. |
_NoValue
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The n-th differences. The shape of the output is the same
as the current array except along the batch axis where
the dimension is smaller by |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = BatchedArray(np.array([[6, 3], [6, 2], [7, 9], [0, 0], [6, 7]]))
>>> ba.diff_along_batch(batch, n=1)
array([[ 0, -1],
[ 1, 7],
[-7, -9],
[ 6, 7]])
>>> batch = BatchedArray(np.array([[9, 3, 7, 4, 0], [6, 6, 2, 3, 3]]), batch_axis=1)
>>> ba.diff_along_batch(batch, n=1)
array([[-6, 4, -3, -4], [ 0, -4, 1, 0]])
redcat.ba.empty ¶
empty(
shape: int | Sequence[int],
dtype: DTypeLike = None,
order: str = "C",
*,
batch_axis: int = 0,
**kwargs: Any
) -> BatchedArray
Return a new array of given shape and type, without initializing entries.
Equivalent of numpy.empty
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape
|
int | Sequence[int]
|
Shape of the new array, e.g., |
required |
dtype
|
DTypeLike
|
The desired data-type for the array. |
None
|
order
|
str
|
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory. |
'C'
|
batch_axis
|
int
|
Specifies the batch axis in the array object. |
0
|
**kwargs
|
Any
|
See the documentation of |
{}
|
Returns:
Type | Description |
---|---|
BatchedArray
|
An array object satisfying the specified requirements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.empty((2, 3))
>>> batch
array([...], batch_axis=0)
redcat.ba.empty_like ¶
empty_like(
a: TBatchedArray,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> TBatchedArray
Return an array of zeros with the same shape and type as a given array.
Equivalent of numpy.empty_like
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The shape and data-type of a define these same attributes of the returned array. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. 'C' means
C-order, 'F' means F-order, 'A' means 'F' if |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order='K' and the number of dimensions is unchanged, will try to keep order, otherwise, order='C' is implied. |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
Array of zeros with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 3))
>>> ba.empty_like(array).shape
(2, 3)
>>> ba.empty_like(array, batch_size=5).shape
(5, 3)
redcat.ba.full ¶
full(
shape: int | Sequence[int],
fill_value: float | ArrayLike,
dtype: DTypeLike = None,
order: str = "C",
*,
batch_axis: int = 0,
**kwargs: Any
) -> BatchedArray
Return a new array of given shape and type, filled with
fill_value
.
Equivalent of numpy.full
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape
|
int | Sequence[int]
|
Shape of the new array, e.g., |
required |
fill_value
|
float | ArrayLike
|
Specifies the fill value. |
required |
dtype
|
DTypeLike
|
The desired data-type for the array. |
None
|
order
|
str
|
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory. |
'C'
|
batch_axis
|
int
|
Specifies the batch axis in the array object. |
0
|
**kwargs
|
Any
|
See the documentation of |
{}
|
Returns:
Type | Description |
---|---|
BatchedArray
|
An array object satisfying the specified requirements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.full((2, 3), fill_value=42)
>>> batch
array([[42, 42, 42],
[42, 42, 42]], batch_axis=0)
redcat.ba.full_like ¶
full_like(
a: TBatchedArray,
fill_value: ArrayLike,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> TBatchedArray
Return an array of ones with the same shape and type as a given array.
Equivalent of numpy.full_like
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The shape and data-type of a define these same attributes of the returned array. |
required |
fill_value
|
ArrayLike
|
Specifies the fill value. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. 'C' means
C-order, 'F' means F-order, 'A' means 'F' if |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order='K' and the number of dimensions is unchanged, will try to keep order, otherwise, order='C' is implied. |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
Array of ones with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.zeros((2, 5))
>>> ba.full_like(array, fill_value=2)
array([[2., 2., 2., 2., 2.],
[2., 2., 2., 2., 2.]], batch_axis=0)
>>> ba.full_like(array, fill_value=42, batch_size=5)
array([[42., 42., 42., 42., 42.],
[42., 42., 42., 42., 42.],
[42., 42., 42., 42., 42.],
[42., 42., 42., 42., 42.],
[42., 42., 42., 42., 42.]], batch_axis=0)
redcat.ba.get_batch_axes ¶
get_batch_axes(
args: Iterable[Any],
kwargs: Mapping[str, Any] | None = None,
) -> set[int]
Return batch axes from the inputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
Iterable[Any]
|
Variable length argument list. |
required |
kwargs
|
Mapping[str, Any] | None
|
Arbitrary keyword arguments. |
None
|
Returns:
Type | Description |
---|---|
set[int]
|
The batch axes. |
Example usage:
>>> from redcat import ba
>>> from redcat.ba import get_batch_axes
>>> get_batch_axes(
... args=(ba.ones((2, 3)), ba.ones((2, 6))),
... kwargs={"batch": ba.ones((2, 4))},
... )
{0}
redcat.ba.max ¶
max(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.max(batch)
6
>>> ba.max(batch, axis=0)
array([3, 6, 5])
>>> ba.max(batch, axis=0, keepdims=True)
array([[3, 6, 5]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.max(batch, axis=1)
array([6, 5])
redcat.ba.max_along_batch ¶
max_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.max_along_batch(batch)
array([3, 6, 5])
>>> ba.max_along_batch(batch, keepdims=True)
array([[3, 6, 5]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.max_along_batch(batch)
array([6, 5])
redcat.ba.mean ¶
mean(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the arithmetic mean along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The arithmetic mean along the specified axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.mean(batch)
3.5
>>> ba.mean(batch, axis=0)
array([2. , 5. , 3.5])
>>> ba.mean(batch, axis=0, keepdims=True)
array([[2. , 5. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.mean(batch, axis=1)
array([3., 4.])
redcat.ba.mean_along_batch ¶
mean_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return tne arithmetic mean along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The arithmetic mean along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.mean_along_batch(batch)
array([2. , 5. , 3.5])
>>> ba.mean_along_batch(batch, keepdims=True)
array([[2. , 5. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.mean_along_batch(batch)
array([3., 4.])
redcat.ba.median ¶
median(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the median along the specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The median along the specified axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.mean(batch)
3.5
>>> ba.mean(batch, axis=0)
array([2. , 5. , 3.5])
>>> ba.mean(batch, axis=0, keepdims=True)
array([[2. , 5. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.mean(batch, axis=1)
array([3., 4.])
redcat.ba.median_along_batch ¶
median_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return tne median along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The median along the specified axis. If the input contains integers or floats smaller than float64, then the output data-type is np.float64. Otherwise, the data-type of the output is the same as that of the input. If out is specified, that array is returned instead. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.mean_along_batch(batch)
array([2. , 5. , 3.5])
>>> ba.mean_along_batch(batch, keepdims=True)
array([[2. , 5. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.mean_along_batch(batch)
array([3., 4.])
redcat.ba.min ¶
min(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.min(batch)
1
>>> ba.min(batch, axis=0)
array([1, 4, 2])
>>> ba.min(batch, axis=0, keepdims=True)
array([[1, 4, 2]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.min(batch, axis=1)
array([1, 3])
redcat.ba.min_along_batch ¶
min_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.min_along_batch(batch)
array([1, 4, 2])
>>> ba.min_along_batch(batch, keepdims=True)
array([[1, 4, 2]])
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.min_along_batch(batch)
array([1, 3])
redcat.ba.nanargmax ¶
nanargmax(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
See numpy.nanargmax
documentation.
redcat.ba.nanargmax_along_batch ¶
nanargmax_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the maximum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the maximum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanargmax_along_batch(batch)
array([1, 1, 1])
>>> ba.nanargmax_along_batch(batch, keepdims=True)
array([[1, 1, 1]])
redcat.ba.nanargmin ¶
nanargmin(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
See numpy.nanargmin
documentation.
redcat.ba.nanargmin_along_batch ¶
nanargmin_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
*,
keepdims: bool = False
) -> ndarray
Return the indices of the minimum values along the batch axis ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. |
None
|
keepdims
|
bool
|
If 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 array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The indices of the minimum values along the batch axis ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanargmin_along_batch(batch)
array([0, 1, 0])
>>> ba.nanargmin_along_batch(batch, keepdims=True)
array([[0, 1, 0]])
redcat.ba.nancumprod ¶
nancumprod(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> TBatchedArray | ndarray
See numpy.nancumprod
documentation.
redcat.ba.nancumprod_along_batch ¶
nancumprod_along_batch(
a: TBatchedArray, dtype: DTypeLike = None
) -> TBatchedArray
Return the cumulative product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The cumulative product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nancumprod_along_batch(batch)
array([[ 1., 1., 2.],
[ 3., 4., 10.]], batch_axis=0)
redcat.ba.nancumsum ¶
nancumsum(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
) -> TBatchedArray | ndarray
See numpy.nancumsum
documentation.
redcat.ba.nancumsum_along_batch ¶
nancumsum_along_batch(
a: TBatchedArray, dtype: DTypeLike = None
) -> TBatchedArray
Return the cumulative sum of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The cumulative sum of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nancumsum_along_batch(batch)
array([[1., 0., 2.],
[4., 4., 7.]], batch_axis=0)
redcat.ba.nanmax ¶
nanmax(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum of an array or maximum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum of an array or maximum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmax(batch)
5.0
>>> ba.nanmax(batch, axis=0)
array([3., 4., 5.])
>>> ba.nanmax(batch, axis=0, keepdims=True)
array([[3., 4., 5.]])
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmax(batch, axis=1)
array([2., 5.])
redcat.ba.nanmax_along_batch ¶
nanmax_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the maximum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The maximum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmax_along_batch(batch)
array([3., 4., 5.])
>>> ba.nanmax_along_batch(batch, keepdims=True)
array([[3., 4., 5.]])
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmax_along_batch(batch)
array([2., 5.])
redcat.ba.nanmean ¶
nanmean(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the arithmetic mean along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The arithmetic mean along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmean(batch)
3.0
>>> ba.nanmean(batch, axis=0)
array([2. , 4. , 3.5])
>>> ba.nanmean(batch, axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> ba.nanmean(batch, axis=1)
array([1.5, 4. ])
redcat.ba.nanmean_along_batch ¶
nanmean_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return tne arithmetic mean along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The arithmetic mean along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmean_along_batch(batch)
array([2. , 4. , 3.5])
>>> ba.nanmean_along_batch(batch, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmean_along_batch(batch)
array([1.5, 4. ])
redcat.ba.nanmedian ¶
nanmedian(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the median along the specified axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The median along the specified axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmedian(batch)
3.0
>>> ba.nanmedian(batch, axis=0)
array([2. , 4. , 3.5])
>>> ba.nanmedian(batch, axis=0, keepdims=True)
array([[2. , 4. , 3.5]])
>>> ba.nanmedian(batch, axis=1)
array([1.5, 4. ])
redcat.ba.nanmedian_along_batch ¶
nanmedian_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return tne median along the batch axis, ignoring NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The median along the batch axis, ignoring NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanmedian_along_batch(batch)
array([2. , 4. , 3.5])
>>> ba.nanmedian_along_batch(batch, keepdims=True)
array([[2. , 4. , 3.5]])
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmedian_along_batch(batch)
array([1.5, 4. ])
redcat.ba.nanmin ¶
nanmin(
a: TBatchedArray,
axis: SupportsIndex | None = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum of an array or minimum along an axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis or axes along which to operate. By default, flattened input is used. |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum of an array or minimum along an axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> ba.nanmin(batch)
2.0
>>> ba.nanmin(batch, axis=0)
array([3., 4., 2.])
>>> ba.nanmin(batch, axis=0, keepdims=True)
array([[3., 4., 2.]])
>>> batch = ba.BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmin(batch, axis=1)
array([2., 3.])
redcat.ba.nanmin_along_batch ¶
nanmin_along_batch(
a: TBatchedArray,
out: ndarray | None = None,
keepdims: bool = False,
) -> ndarray
Return the minimum along the batch axis, ignoring any NaNs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The minimum along the batch axis, ignoring any NaNs. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]))
>>> ba.nanmin_along_batch(batch)
array([3., 4., 2.])
>>> ba.nanmin_along_batch(batch, keepdims=True)
array([[3., 4., 2.]])
>>> batch = ba.BatchedArray(np.array([[np.nan, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanmin_along_batch(batch)
array([2., 3.])
redcat.ba.nanprod ¶
nanprod(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> TBatchedArray | ndarray
Return the product of elements along a given axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The product of elements along a given axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanprod(batch, axis=0)
array([ 3., 4., 10.])
>>> ba.nanprod(batch, axis=0, keepdims=True)
array([[ 3., 4., 10.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nanprod(batch, axis=1)
array([ 2., 60.])
redcat.ba.nanprod_along_batch ¶
nanprod_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
keepdims: bool = False,
) -> TBatchedArray
Return the product of elements along the batch axis treating Not a Numbers (NaNs) as one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The product of elements along the batch axis treating Not a Numbers (NaNs) as one. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nanprod_along_batch(batch)
array([ 3., 4., 10.])
redcat.ba.nansum ¶
nansum(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> TBatchedArray | ndarray
Return the sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nansum(batch, axis=0)
array([4., 4., 7.])
>>> ba.nansum(batch, axis=0, keepdims=True)
array([[4., 4., 7.]])
>>> batch = BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.nansum(batch, axis=1)
array([ 3., 12.])
redcat.ba.nansum_along_batch ¶
nansum_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
keepdims: bool = False,
) -> TBatchedArray
Return the sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, np.nan, 2], [3, 4, 5]]))
>>> ba.nansum_along_batch(batch)
array([4., 4., 7.])
redcat.ba.ones ¶
ones(
shape: int | Sequence[int],
dtype: DTypeLike = None,
order: str = "C",
*,
batch_axis: int = 0,
**kwargs: Any
) -> BatchedArray
Return a new array of given shape and type, filled with ones.
Equivalent of numpy.ones
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape
|
int | Sequence[int]
|
Shape of the new array, e.g., |
required |
dtype
|
DTypeLike
|
The desired data-type for the array. |
None
|
order
|
str
|
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory. |
'C'
|
batch_axis
|
int
|
Specifies the batch axis in the array object. |
0
|
**kwargs
|
Any
|
See the documentation of |
{}
|
Returns:
Type | Description |
---|---|
BatchedArray
|
An array object satisfying the specified requirements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.ones((2, 3))
>>> batch
array([[1., 1., 1.],
[1., 1., 1.]], batch_axis=0)
redcat.ba.ones_like ¶
ones_like(
a: TBatchedArray,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> TBatchedArray
Return an array of ones with the same shape and type as a given array.
Equivalent of numpy.ones_like
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The shape and data-type of a define these same attributes of the returned array. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. 'C' means
C-order, 'F' means F-order, 'A' means 'F' if |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order='K' and the number of dimensions is unchanged, will try to keep order, otherwise, order='C' is implied. |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
Array of ones with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.zeros((2, 5))
>>> ba.ones_like(array)
array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]], batch_axis=0)
>>> ba.ones_like(array, batch_size=5)
array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]], batch_axis=0)
redcat.ba.prod ¶
prod(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> TBatchedArray | ndarray
Return the product of elements along a given axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The product of elements along a given axis treating. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.prod(batch, axis=0)
array([ 3, 24, 10])
>>> ba.prod(batch, axis=0, keepdims=True)
array([[ 3, 24, 10]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.prod(batch, axis=1)
array([12, 60])
redcat.ba.prod_along_batch ¶
prod_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
keepdims: bool = False,
) -> TBatchedArray
Return the product of elements along the batch axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type of the returned array and of the accumulator
in which the elements are multiplied. If dtype is not
specified, it defaults to the dtype of |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The product of elements along the batch axis. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.prod_along_batch(batch)
array([ 3, 24, 10])
redcat.ba.sort_along_batch ¶
sort_along_batch(
a: TBatchedArray, kind: SortKind | None = None
) -> TBatchedArray
Sort an array along the batch dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
kind
|
SortKind | None
|
Sorting algorithm. The default is 'quicksort'. Note that both 'stable' and 'mergesort' use timsort under the covers and, in general, the actual implementation will vary with datatype. The 'mergesort' option is retained for backwards compatibility. |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
A sorted copy of an array. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.sort_along_batch(batch)
array([[1, 4, 2],
[3, 6, 5]], batch_axis=0)
redcat.ba.sum ¶
sum(
a: TBatchedArray,
axis: SupportsIndex | None = None,
dtype: DTypeLike = None,
out: ndarray | None = None,
keepdims: bool = False,
) -> TBatchedArray | ndarray
Return the sum of elements along a given axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
axis
|
SupportsIndex | None
|
Axis along which the cumulative product is computed. By default, the input is flattened. |
None
|
dtype
|
DTypeLike
|
Type 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 |
None
|
out
|
ndarray | None
|
Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary. |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray | ndarray
|
The sum of elements along a given axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.sum(batch, axis=0)
array([ 4, 10, 7])
>>> ba.sum(batch, axis=0, keepdims=True)
array([[ 4, 10, 7]])
>>> batch = BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]), batch_axis=1)
>>> ba.sum(batch, axis=1)
array([ 9, 12])
redcat.ba.sum_along_batch ¶
sum_along_batch(
a: TBatchedArray,
dtype: DTypeLike = None,
keepdims: bool = False,
) -> TBatchedArray
Return the sum of elements along the batch axis treating Not a Numbers (NaNs) as zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The input array. |
required |
dtype
|
DTypeLike
|
Type 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 |
None
|
keepdims
|
bool
|
If 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 original array. |
False
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
The sum of elements along the batch axis treating Not a Numbers (NaNs) as zero. |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> batch = ba.BatchedArray(np.array([[1, 6, 2], [3, 4, 5]]))
>>> ba.sum_along_batch(batch)
array([ 4, 10, 7])
redcat.ba.zeros ¶
zeros(
shape: int | Sequence[int],
dtype: DTypeLike = None,
order: str = "C",
*,
batch_axis: int = 0,
**kwargs: Any
) -> BatchedArray
Return a new array of given shape and type, filled with zeros.
Equivalent of numpy.zeros
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape
|
int | Sequence[int]
|
Shape of the new array, e.g., |
required |
dtype
|
DTypeLike
|
The desired data-type for the array. |
None
|
order
|
str
|
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory. |
'C'
|
batch_axis
|
int
|
Specifies the batch axis in the array object. |
0
|
**kwargs
|
Any
|
See the documentation of |
{}
|
Returns:
Type | Description |
---|---|
BatchedArray
|
An array object satisfying the specified requirements. |
Example usage:
>>> from redcat import ba
>>> batch = ba.zeros((2, 3))
>>> batch
array([[0., 0., 0.],
[0., 0., 0.]], batch_axis=0)
redcat.ba.zeros_like ¶
zeros_like(
a: TBatchedArray,
dtype: DTypeLike = None,
order: OrderACFK = "K",
subok: bool = True,
shape: ShapeLike = None,
batch_size: int | None = None,
) -> TBatchedArray
Return an array of zeros with the same shape and type as a given array.
Equivalent of numpy.zeros_like
for BatchedArray
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
TBatchedArray
|
The shape and data-type of a define these same attributes of the returned array. |
required |
dtype
|
DTypeLike
|
Overrides the data type of the result. |
None
|
order
|
OrderACFK
|
Overrides the memory layout of the result. 'C' means
C-order, 'F' means F-order, 'A' means 'F' if |
'K'
|
subok
|
bool
|
If True, then the newly created array will use the
sub-class type of |
True
|
shape
|
ShapeLike
|
Overrides the shape of the result. If order='K' and the number of dimensions is unchanged, will try to keep order, otherwise, order='C' is implied. |
None
|
batch_size
|
int | None
|
Overrides the batch size. If |
None
|
Returns:
Type | Description |
---|---|
TBatchedArray
|
Array of zeros with the same shape and type as |
Example usage:
>>> import numpy as np
>>> from redcat import ba
>>> array = ba.ones((2, 5))
>>> ba.zeros_like(array)
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], batch_axis=0)
>>> ba.zeros_like(array, batch_size=5)
array([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]], batch_axis=0)