V
- The type of the items stored in the Nda
.public interface Nda<V> extends NDimensional, java.lang.Iterable<V>
Modifier and Type | Interface and Description |
---|---|
static interface |
Nda.Item<V>
Instances of this are being returned by the
at(int...) method,
and they allow you to get individual nd-array items |
Modifier and Type | Method and Description |
---|---|
default boolean |
any(java.util.function.Predicate<V> predicate)
Iterates over every element of this nd-array, and checks whether any
element matches the provided lambda.
|
Nda.Item<V> |
at(int... indices)
This method exposes the
Nda.Item API which allows you to get or set
individual items within this nd-array targeted by an array of provided indices. |
Nda<V> |
concatAt(int axis,
Nda<V> other)
This method concatenates the provided nd-array together with this nd-array along a specified axis.
|
Nda<V> |
concatAt(int axis,
Nda<V> other,
Nda<V>... ndArrays)
This method concatenates the provided nd-arrays together with this nd-array along a specified axis.
|
default int |
count(java.util.function.Predicate<V> predicate)
Iterates over every element of this nd-array, and counts the number of
times the provided lambda matches the items of this array.
|
Nda<V> |
deepCopy()
This method creates and returns a new nd-array instance
which is not only a copy of the configuration of this nd-array but also a copy of
the underlying data array.
|
default boolean |
every(java.util.function.Predicate<V> predicate)
Iterates over every element of this nd-array, and checks whether all
elements are
true according to the provided lambda. |
default java.util.stream.Stream<V> |
filter(java.util.function.Predicate<V> predicate)
A convenience method for
stream().filter( predicate ) . |
default <R> java.util.stream.Stream<R> |
flatMap(java.util.function.Function<V,java.util.stream.Stream<R>> mapper)
A convenience method for
nda.stream().flatMap( mapper ) ,
which turns this Nda into a Stream of its items. |
Nda<V> |
get(int... indices)
The following method enables access to specific scalar elements within the nd-array.
|
Nda<V> |
get(int i)
This getter method creates and returns a slice of the original nd-array.
|
Nda<V> |
get(java.lang.Number i)
This getter method creates and returns a slice of the original nd-array.
|
Nda<V> |
get(java.lang.Object... args)
The following method enables the creation of nd-array slices which access
the same underlying data (possibly from a different view).
|
Nda<V> |
get(java.lang.Object key)
This method enables nd-array slicing!
It takes a key of various types and configures a slice
nd-array which shares the same underlying data as the original nd-array.
|
Nda<V> |
getAt(int... indices)
The following method enables access to specific scalar elements within the nd-array.
|
Nda<V> |
getAt(int i)
This getter method creates and returns a slice of the original nd-array.
|
Nda<V> |
getAt(java.util.List<?> key)
This method enables nd-array slicing!
It takes a key of various types and configures a slice
nd-array which shares the same underlying data as the original nd-array.
|
Nda<V> |
getAt(java.util.Map<?,java.lang.Integer> rangToSteps)
This method is most useful when used in Groovy
where defining maps is done through square brackets,
making it possible to slice nd-arrays like so:
|
Nda<V> |
getAt(java.lang.Number i)
This getter method creates and returns a slice of the original nd-array.
|
Nda<V> |
getAt(java.lang.Object... args)
The following method enables the creation of nd-array slices which access
the same underlying data (possibly from a different view).
|
default <A> A |
getDataAs(java.lang.Class<A> arrayTypeClass)
Use this to get the items of the underlying
Data buffer
of this nd-array as a primitive array
of the specified type. |
V |
getDataAt(int i)
Use this to access elements of the underlying data array without any index
transformation applied to it.
|
default V |
getItem()
Equivalent to the
#item(0) and item() . |
default java.util.List<V> |
getItems()
A more verbose version of the
items() method (best used by JVM languages with property support). |
default <A> A |
getItemsAs(java.lang.Class<A> arrayTypeClass)
Use this to get the items of this nd-array as a primitive array
of the specified type.
|
java.lang.Class<V> |
getItemType() |
default java.lang.String |
getLabel()
A nd-array can have a label.
|
MutateNda<V> |
getMut()
This method exposes an API for mutating the state of this tensor.
|
java.lang.Object |
getRawData()
This returns an unprocessed version of the underlying data of this nd-array.
|
java.lang.Object |
getRawItems() |
default boolean |
isFullSlice()
If this nd-array is a full slice of a parent nd-array then this method will yield true.
|
boolean |
isPartialSlice()
If this nd-array is a partial slice of a parent nd-array then this method will yield true.
|
boolean |
isShallowCopy()
If this nd-array is a shallow copy of a parent nd-array then this method will yield true.
|
boolean |
isSlice()
If this nd-array is a slice of a parent nd-array then this method will yield true.
|
boolean |
isSliceParent()
If slices have been derived from this nd-array then it is a "slice parent".
|
default V |
item()
Equivalent to the
#item(0) and getItem() . |
default V |
item(int... indices)
This method returns a raw value item within this nd-array
targeted by an index array which is expected to hold an index for
every dimension of the shape of this nd-array.
|
default V |
item(int i)
The following method returns a single item within this nd-array
targeted by the provided integer index.
|
default java.util.List<V> |
items()
A more concise version of the
getItems() method. |
default java.lang.Class<V> |
itemType() |
default java.lang.String |
label()
A nd-array can have a label.
|
Nda<V> |
map(java.util.function.Function<V,V> mapper)
This method is a convenience method for mapping the items of this nd-array to another
nd-array of the same type based on the provided lambda function, which will be applied
to all items of this nd-array individually (element-wise).
|
<T> Nda<T> |
mapTo(java.lang.Class<T> typeClass,
java.util.function.Function<V,T> mapper)
This is a convenience method for mapping a nd-array to a nd-array of new type
based on a provided target item type and mapping lambda.
|
default V |
maxItem(java.util.Comparator<V> comparator)
Returns the maximum item of this nd-array according to the provided
Comparator . |
default V |
minItem(java.util.Comparator<V> comparator)
Returns the minimum item of this nd-array according to the provided
Comparator . |
default MutateNda<V> |
mut()
This method exposes an API for mutating the state of this tensor.
|
default boolean |
none(java.util.function.Predicate<V> predicate)
Iterates over every element of this nd-array, and checks whether none
of the elements match the provided lambda.
|
static Nda<java.lang.Boolean> |
of(boolean... value)
Constructs a vector of booleans based on the provided array.
|
static Nda<java.lang.Byte> |
of(byte... value)
Constructs a vector of bytes based on the provided array.
|
static <V> WithShapeOrScalarOrVector<V> |
of(java.lang.Class<V> type)
This is the entry point to the fluent nd-array builder API for building
Nda instances in a readable and type safe fashion. |
static Nda<java.lang.Double> |
of(double... value)
Constructs a vector of doubles based on the provided array.
|
static Nda<java.lang.Double> |
of(double value) |
static Nda<java.lang.Float> |
of(float... value)
Constructs a vector of floats based on the provided array.
|
static Nda<java.lang.Integer> |
of(int... value)
Constructs a vector of ints based on the provided array.
|
static <T> Nda<T> |
of(java.lang.Iterable<T> values)
Constructs a vector of objects based on the provided iterable.
|
static <T> Nda<T> |
of(java.util.List<T> values)
Constructs a vector of objects based on the provided list.
|
static Nda<java.lang.Long> |
of(long... value)
Constructs a vector of longs based on the provided array.
|
static Nda<java.lang.Boolean> |
of(Shape shape,
boolean... values)
Use this to construct and return a boolean based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Byte> |
of(Shape shape,
byte... values)
Use this to construct and return a byte based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Double> |
of(Shape shape,
double... values)
Use this to construct and return a double based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Float> |
of(Shape shape,
float... values)
Use this to construct and return a float based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Integer> |
of(Shape shape,
int... values)
Use this to construct and return a int based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Long> |
of(Shape shape,
long... values)
Use this to construct and return a long based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Short> |
of(Shape shape,
short... values)
Use this to construct and return a short based nd-array of the specified shape and initial values.
|
static <T> Nda<T> |
of(Shape shape,
T... values)
Use this to construct and return an object based nd-array of the specified shape and initial values.
|
static Nda<java.lang.Short> |
of(short... value)
Constructs a vector of shorts based on the provided array.
|
static <T> Nda<T> |
of(T... values)
Constructs a vector of objects based on the provided array.
|
static WithShapeOrScalarOrVector<java.math.BigDecimal> |
ofBigDecimals()
|
static WithShapeOrScalarOrVector<java.lang.Boolean> |
ofBooleans()
|
static WithShapeOrScalarOrVector<java.lang.Byte> |
ofBytes()
|
static WithShapeOrScalarOrVector<java.lang.Character> |
ofChars()
|
static WithShapeOrScalarOrVector<java.lang.Double> |
ofDoubles()
|
static WithShapeOrScalarOrVector<java.lang.Float> |
ofFloats()
|
static WithShapeOrScalarOrVector<java.lang.Integer> |
ofInts()
|
static WithShapeOrScalarOrVector<java.lang.Long> |
ofLongs()
|
static WithShapeOrScalarOrVector<java.lang.Number> |
ofNumbers()
|
static WithShapeOrScalarOrVector<java.lang.Object> |
ofObjects()
|
static WithShapeOrScalarOrVector<java.lang.Short> |
ofShorts()
|
static WithShapeOrScalarOrVector<java.lang.String> |
ofStrings()
|
Nda<V> |
permute(int... dims)
Returns a view of the original tensor input with its dimensions permuted.
Consider a 3-dimensional tensor x with shape (2×3×5), then calling x.permute(1, 0, 2) will return a 3-dimensional tensor of shape (3×2×5). |
Nda<V> |
reshape(int... shape)
Returns a nd-array with the same data and number of elements as this nd-array, but with the specified shape.
|
Nda<V> |
shallowCopy()
This creates a copy where the underlying data is still the same.
|
static <T> java.util.stream.Collector<T,?,Nda<T>> |
shaped(int... shape)
Returns a
Collector that accumulates the input elements into a
new Nda with the specified shape. |
AxisOrGet<V> |
slice()
This method returns a
SliceBuilder instance exposing a simple builder API
which enables the configuration of a slice of the current nd-array via method chaining. |
int |
sliceCount()
This method returns the number of slices which have been
created from this nd-array.
|
default java.util.stream.Stream<V> |
stream() |
java.lang.String |
toString()
This method returns a
String representation of this nd-array. |
default java.lang.String |
toString(java.util.function.Consumer<NDPrintSettings> config)
This allows you to provide a lambda which configures how this nd-array should be
converted to
String instances. |
default java.lang.String |
toString(NDPrintSettings config)
Use this to turn this nd-array into a
String instance based on the provided
NDPrintSettings instance, which allows you to configure things
like the number of chars per entry, delimiters, the number of items per line, etc. |
Nda<V> |
transpose(int dim1,
int dim2)
Returns a view of the original tensor input the targeted
axes are swapped / transposed.
|
Nda<V> |
withLabel(java.lang.String label) |
Nda<V> |
withLabels(java.util.List<java.util.List<java.lang.Object>> labels)
This method receives a nested
String list which
ought to contain a label for the index of this nd-array. |
Nda<V> |
withLabels(java.util.Map<java.lang.Object,java.util.List<java.lang.Object>> labels)
This method provides the ability to
label not only the indices of the shape of this nd-array, but also
the dimension of the shape.
|
Nda<V> |
withLabels(java.lang.String[]... labels)
This method receives a nested
String array which
ought to contain a label for the index of this nd-array. |
getNDConf, getRank, getShape, getSize, indexOfIndex, indexOfIndices, indicesMap, indicesOfIndex, offset, rank, shape, shape, size, spread, strides
static <V> WithShapeOrScalarOrVector<V> of(java.lang.Class<V> type)
Nda
instances in a readable and type safe fashion.
The returned WithShapeOrScalarOrVector
is the next step in the
fluent Nda
builder API which will lead to the creation
of an nd-array storing values defined by the provided type class.
A simple usage example would be:
Nda.of(Double.class)
.withShape( 2, 3, 4 )
.andFill( 5, 3, 5 )
It is also possible to define a range using the API to populate the nd-array with values:
Nda.of(Double.class)
.withShape( 2, 3, 4 )
.andFillFrom( 2 ).to( 9 ).step( 2 )
If one needs a simple scalar then the following shortcut is possible:
Nda.of(Float.class).scalar( 3f )
This principle works for vectors as well:
Nda.of(Byte.class).vector( 2, 5, 6, 7, 8 )
For more fine-grained control over the initialization one can
pass an initialization lambda to the API:
Nda.of(Byte.class).withShape(2, 3).andWhere( (i, indices) -> i * 5 - 30 )
type
- The type class of the items stored by the nd-array built by the exposed builder API.Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.String> ofStrings()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Integer> ofInts()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Double> ofDoubles()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Float> ofFloats()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Long> ofLongs()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Boolean> ofBooleans()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Character> ofChars()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Byte> ofBytes()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Short> ofShorts()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Object> ofObjects()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.lang.Number> ofNumbers()
Nda
builder API which exposes methods for defining shapes.static WithShapeOrScalarOrVector<java.math.BigDecimal> ofBigDecimals()
Nda
builder API which exposes methods for defining shapes.static Nda<java.lang.Double> of(double value)
value
- The scalar value which ought to be represented as nd-array.static Nda<java.lang.Float> of(float... value)
value
- The array of floats from which a 1D nd-array ought to be constructed.static Nda<java.lang.Double> of(double... value)
value
- The array of doubles from which a 1D nd-array ought to be constructed.static Nda<java.lang.Byte> of(byte... value)
value
- The array of bytes from which a 1D nd-array ought to be constructed.static Nda<java.lang.Integer> of(int... value)
value
- The array of ints from which a 1D nd-array ought to be constructed.static Nda<java.lang.Long> of(long... value)
value
- The array of longs from which a 1D nd-array ought to be constructed.static Nda<java.lang.Short> of(short... value)
value
- The array of shorts from which a 1D nd-array ought to be constructed.static Nda<java.lang.Boolean> of(boolean... value)
value
- The array of booleans from which a 1D nd-array ought to be constructed.@SafeVarargs static <T> Nda<T> of(T... values)
values
- The array of objects from which a 1D nd-array ought to be constructed.static Nda<java.lang.Double> of(Shape shape, double... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Float> of(Shape shape, float... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Byte> of(Shape shape, byte... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Integer> of(Shape shape, int... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Long> of(Shape shape, long... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Short> of(Shape shape, short... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static Nda<java.lang.Boolean> of(Shape shape, boolean... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.@SafeVarargs static <T> Nda<T> of(Shape shape, T... values)
shape
- The shape of the resulting nd-array consisting of any number of axis-sizes.values
- The values which ought to be used to populate the tensor.static <T> Nda<T> of(java.lang.Iterable<T> values)
values
- The iterable of objects from which a 1D nd-array ought to be constructed.static <T> Nda<T> of(java.util.List<T> values)
values
- The list of objects from which a 1D nd-array ought to be constructed.default java.lang.String getLabel()
default java.lang.String label()
getLabel()
.boolean isSlice()
getAt(int...)
" method.getAt(int...)
,
slice()
boolean isShallowCopy()
shallowCopy()
" method.shallowCopy()
boolean isPartialSlice()
getAt(int...)
" method.
This is the inverse of isFullSlice()
.default boolean isFullSlice()
getAt(int...)
" method.
This is the inverse of isPartialSlice()
.int sliceCount()
Relation
component if present
which internally keeps track of slices via weak references.boolean isSliceParent()
java.lang.Class<V> getItemType()
default java.lang.Class<V> itemType()
Nda<V> withLabel(java.lang.String label)
Nda<V> withLabels(java.lang.String[]... labels)
String
array which
ought to contain a label for the index of this nd-array.
The index for a single element of this nd-array would be an array
of numbers as long as the rank where every number is
in the range of the corresponding shape dimension...
Labeling an index means that for every dimension there
must be a label for elements in this range array! labels
- A nested String array containing labels for indexes of the nd-array dimensions.Nda<V> withLabels(java.util.List<java.util.List<java.lang.Object>> labels)
String
list which
ought to contain a label for the index of this nd-array.
The index for a single element of this nd-array would be an array
of numbers as long as the rank where every number is
in the range of the corresponding shape dimension...
Labeling an index means that for every dimension there
must be a label for elements in this range array! labels
- A nested String list containing labels for indexes of the nd-array dimensions.Nda<V> withLabels(java.util.Map<java.lang.Object,java.util.List<java.lang.Object>> labels)
labels
- A map in which the keys are dimension labels and the values are lists of index labels for the dimension.default java.util.stream.Stream<V> filter(java.util.function.Predicate<V> predicate)
stream().filter( predicate )
.default <R> java.util.stream.Stream<R> flatMap(java.util.function.Function<V,java.util.stream.Stream<R>> mapper)
nda.stream().flatMap( mapper )
,
which turns this Nda
into a Stream
of its items.
var nda = Nda.of( -2, -1, 0, 1, 2 );
var list = nda.flatMap( i -> Stream.of( i * 2, i * 3 ) ).toList();
// list = [-4, -6, -2, -3, 0, 0, 2, 3, 4, 6, 6, 9]
static <T> java.util.stream.Collector<T,?,Nda<T>> shaped(int... shape)
Collector
that accumulates the input elements into a
new Nda
with the specified shape.
var nda = Stream.of( 1, 2, 3, 4, 5, 6 )
.collect( Nda.shaped( 2, 3 ) );
T
- the type of the input elementsshape
- The shape of the nd-array to be returned.Collector
which collects all the input elements into a
Nda
, in encounter order.default boolean every(java.util.function.Predicate<V> predicate)
true
according to the provided lambda.predicate
- The lambda to check each element against.default boolean any(java.util.function.Predicate<V> predicate)
predicate
- The lambda to check each element against.default boolean none(java.util.function.Predicate<V> predicate)
predicate
- The lambda to check each element against.default int count(java.util.function.Predicate<V> predicate)
Here is an example of counting the number of items in the array that are greater than 5 :
var nda = Nda.of( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
var count = nda.count( i -> i > 5 );
System.out.println( count ); // prints 5
predicate
- The lambda to check each element against.default V minItem(java.util.Comparator<V> comparator)
Comparator
. This is a special case of a reduction.comparator
- The Comparator
to use to determine the order of the items in the nd-array.default V maxItem(java.util.Comparator<V> comparator)
Comparator
. This is a special case of a reduction.comparator
- The Comparator
to use to determine the order of the items in the nd-array.java.lang.Object getRawData()
getItems()
method, this one will
return the data in an unbiased form, where for example a virtual (see Tensor.isVirtual()
)
nd-array will have this method return an array of length 1.V getDataAt(int i)
item(int)
method,
however for nd-arrays which are sliced or permuted views of the data of another nd-array,
this method will always be unbiased access of the raw data...i
- The position of the targeted item within the raw data array of an NDArray implementation.default java.util.List<V> getItems()
items()
method (best used by JVM languages with property support).default java.util.List<V> items()
getItems()
method.java.lang.Object getRawItems()
default V item(int i)
i
- The scalar index of the item which should be returned by the method.default V item(int... indices)
indices
- The index array which targets a single value item within this nd-array.default V item()
#item(0)
and getItem()
.default V getItem()
#item(0)
and item()
.default <A> A getItemsAs(java.lang.Class<A> arrayTypeClass)
A
- The type of the array to return.arrayTypeClass
- The class of the array type to return.default <A> A getDataAs(java.lang.Class<A> arrayTypeClass)
Data
buffer
of this nd-array as a primitive array
of the specified type.
Note that the length of the returned array may be different from the
size of this nd-array. This is the case if this nd-array is a slice
of another larger nd-array.A
- The type of the array to return.arrayTypeClass
- The class of the array type to return.AxisOrGet<V> slice()
SliceBuilder
instance exposing a simple builder API
which enables the configuration of a slice of the current nd-array via method chaining.
myArray.slice()
.axis(0).from(0).to(1)
.axis(1).at(5) // equivalent to '.from(5).to(5)'
.axis().from(0).to(2)
.get();
SliceBuilder
class exposing a readable builder API for creating slices.Nda<V> concatAt(int axis, Nda<V> other, Nda<V>... ndArrays)
axis
- The axis along which the provided nd-arrays should be concatenated.
The axis must be within the range of the rank of the current nd-array.other
- The other nd-arrays which should be concatenated with this nd-array.ndArrays
- The non-null, non-empty nd-arrays which should be concatenated together with this and the other nd-array.
The nd-arrays all must have the same shape as this nd-array, except for the specified axis.
Also, it must have the same data type as the current nd-array.Nda<V> concatAt(int axis, Nda<V> other)
axis
- The axis along which the provided nd-arrays should be concatenated.
The axis must be within the range of the rank of the current nd-array.other
- The other nd-arrays which should be concatenated with this nd-array.Nda<V> getAt(int... indices)
indices
- The index array of the element which should be returned.Nda<V> getAt(java.lang.Number i)
i
- The index of the value item which should be returned as a nd-array instance.Nda<V> get(int... indices)
indices
- The index array of the element which should be returned.Nda<V> getAt(java.lang.Object... args)
args
- An arbitrary number of arguments which can be used for slicing.Nda<V> get(java.lang.Object... args)
args
- An arbitrary number of arguments which can be used for slicing.Nda<V> getAt(int i)
i
- The index of the value item which should be returned as a nd-array instance.Nda<V> get(int i)
i
- The index of the value item which should be returned as a nd-array instance.Nda<V> get(java.lang.Number i)
i
- The index of the value item which should be returned as a nd-array instance.Nda<V> get(java.lang.Object key)
key
- This object might be a wide range of objects including maps, lists or arrays...Nda<V> getAt(java.util.Map<?,java.lang.Integer> rangToSteps)
var b = a[[[0..0]:1, [0..0]:1, [0..3]:2]]
Here a single argument with the format '[i..j]:k' is equivalent
to Pythons 'i:j:k' syntax for indexing! (numpy) rangToSteps
- A map where the keys define where axes should be sliced and values which define the steps for the specific axis.Nda<V> getAt(java.util.List<?> key)
key
- This object might be a wide range of objects including maps, lists or arrays...<T> Nda<T> mapTo(java.lang.Class<T> typeClass, java.util.function.Function<V,T> mapper)
This is a convenience method for mapping a nd-array to a nd-array of new type based on a provided target item type and mapping lambda. Here a simple example:
Nda<String> a = Nda.of(String.class).vector("1", "2", "3");
Nda<Integer> b = a.mapTo(Integer.class, s -> Integer.parseInt(s));
Note:
The provided lambda cannot be executed anywhere else but the CPU.
This is a problem if this nd-array lives somewhere other than the JVM.
So, therefore, this method will temporally transfer this nd-array from
where ever it may reside back to the JVM, execute the mapping lambda, and
then transfer the result back to the original location.
T
- The type parameter of the items of the returned nd-array.typeClass
- The class of the item type to which the items of this nd-array should be mapped.mapper
- The lambda which maps the items of this nd-array to a new one.T
.Nda<V> map(java.util.function.Function<V,V> mapper)
This method is a convenience method for mapping the items of this nd-array to another nd-array of the same type based on the provided lambda function, which will be applied to all items of this nd-array individually (element-wise).
Here a simple example:
Nda<String> a = Nda.of(String.class).vector("1", "2", "3");
Nda<String> b = a.map( s -> s + "!" );
Note: mapper
- The lambda which maps the items of this nd-array to a new one.V
.Nda<V> deepCopy()
Nda<V> shallowCopy()
MutateNda<V> getMut()
Only use this if you know what you are doing and
performance is critical!
(Like in custom backend extensions for example)
default MutateNda<V> mut()
Only use this if you know what you are doing and
performance is critical!
(Like custom backend extensions for example)
Nda<V> reshape(int... shape)
shape
- The new shape of the returned nd-array.Nda<V> permute(int... dims)
dims
- The desired ordering of dimensionsNda<V> transpose(int dim1, int dim2)
dim1
- The first dimension to be swapped.dim2
- The second dimension to be swapped.Nda.Item<V> at(int... indices)
Nda.Item
API which allows you to get or set
individual items within this nd-array targeted by an array of provided indices.indices
- An array of indices targeting a particular position in this nd-array...default java.lang.String toString(NDPrintSettings config)
String
instance based on the provided
NDPrintSettings
instance, which allows you to configure things
like the number of chars per entry, delimiters, the number of items per line, etc.default java.lang.String toString(java.util.function.Consumer<NDPrintSettings> config)
String
instances.
The provided Consumer
will receive a NDPrintSettings
instance
which allows you to change various settings with the help of method chaining.
t.toString(it ->
it.setHasSlimNumbers(false)
.setIsScientific(true)
.setIsCellBound(true)
.setIsMultiline(true)
.setCellSize(15)
);
config
- A consumer of the NDPrintSettings
ready to be configured.String
representation of this nd-array.java.lang.String toString()
String
representation of this nd-array.
The default settings are used for the conversion.toString
in class java.lang.Object
String
representation of this nd-array.