Type Definition ndarray::IxDyn

source ·
pub type IxDyn = Dim<IxDynImpl>;
Expand description

dynamic-dimensional

You can use the IxDyn function to create a dimension for an array with dynamic number of dimensions. (Vec<usize> and &[usize] also implement IntoDimension to produce IxDyn).

use ndarray::ArrayD;
use ndarray::IxDyn;

// Create a 5 × 6 × 3 × 4 array using the dynamic dimension type
let mut a = ArrayD::<f64>::zeros(IxDyn(&[5, 6, 3, 4]));
// Create a 1 × 3 × 4 array using the dynamic dimension type
let mut b = ArrayD::<f64>::zeros(IxDyn(&[1, 3, 4]));

// We can use broadcasting to add arrays of compatible shapes together:
a += &b;

// We can index into a, b using fixed size arrays:
a[[0, 0, 0, 0]] = 0.;
b[[0, 2, 3]] = a[[0, 0, 2, 3]];
// Note: indexing will panic at runtime if the number of indices given does
// not match the array.

// We can keep them in the same vector because both the arrays have
// the same type `Array<f64, IxDyn>` a.k.a `ArrayD<f64>`:
let arrays = vec![a, b];

Implementations§

source§

impl IxDyn

source

pub fn zeros(n: usize) -> IxDyn

Create a new dimension value with n axes, all zeros

Trait Implementations§

source§

impl<D: Dimension> DimAdd<D> for IxDyn

§

type Output = Dim<IxDynImpl>

The sum of the two dimensions.
source§

impl DimMax<Dim<[usize; 0]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 1]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 2]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 3]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 4]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 5]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl DimMax<Dim<[usize; 6]>> for IxDyn

§

type Output = Dim<IxDynImpl>

The resulting dimension type after broadcasting.
source§

impl Dimension for IxDyn

IxDyn is a “dynamic” index, pretty hard to use when indexing, and memory wasteful, but it allows an arbitrary and dynamic number of axes.

source§

const NDIM: Option<usize> = None

For fixed-size dimension representations (e.g. Ix2), this should be Some(ndim), and for variable-size dimension representations (e.g. IxDyn), this should be None.
§

type Pattern = Dim<IxDynImpl>

Pattern matching friendly form of the dimension value. Read more
§

type Smaller = Dim<IxDynImpl>

Next smaller dimension (if applicable)
§

type Larger = Dim<IxDynImpl>

Next larger dimension
source§

fn ndim(&self) -> usize

Returns the number of dimensions (number of axes).
source§

fn into_pattern(self) -> Self::Pattern

Convert the dimension into a pattern matching friendly value.
source§

fn zeros(ndim: usize) -> Self

Creates a dimension of all zeros with the specified ndim. Read more
source§

fn into_dyn(self) -> IxDyn

Convert the dimensional into a dynamic dimensional (IxDyn).
source§

fn size(&self) -> usize

Compute the size of the dimension (number of elements)
source§

fn size_checked(&self) -> Option<usize>

Compute the size while checking for overflow.
source§

fn as_array_view(&self) -> ArrayView1<'_, Ix>

Borrow as a read-only array view.
source§

fn as_array_view_mut(&mut self) -> ArrayViewMut1<'_, Ix>

Borrow as a read-write array view.
source§

impl<'a> NdIndex<Dim<IxDynImpl>> for &'a IxDyn