Questions tagged [rust-ndarray]
54 questions
6
votes
1 answer
Elementary function math opereations for Rust ndarray arrays
I simply would like to do elementary math operations (e.g., sin, exp, log, sqrt ...) for Rust ndarray. However, I did not find any useful example for doing so from reading ndarray's documentations.
Say, for example:
extern crate ndarray;
use…

null
- 1,167
- 1
- 12
- 30
4
votes
0 answers
Good ways to deal with operations that return Result when using Ndarray
Recently I've started using ndarray to handle my multi-dimentional arrays when using Rust, and I love a lot of it's convenience features, if I could just figure out one problem, it would be perfect.
Normally, when you collect an iterator over set a…

Nick Cosby
- 41
- 2
3
votes
1 answer
Updating a row of a matrix in rust ndarray
I was looking to update a row of 2D matrix in rust ndarray, but row_mut does not seem to allow me to update the row directly.
For example (playground link)
let mut array = array![[1., 2.], [3., 4.]];
let y = array![5., 5.];
array.row_mut(0) +=…

Devil
- 903
- 2
- 13
- 21
3
votes
1 answer
What's alternative for roll() in rust Ndarray crate?
There is a roll function in Numpy. But ndarray docs don't mention anything similar.
I am trying to "roll" my array by an integer. For example
let ar = arr2(&[[1.,2.,3.], [7., 8., 9.]]);
calling numpy roll(ar, 1) would produce the desired…

Anatoly Bugakov
- 772
- 1
- 7
- 18
3
votes
0 answers
Rust trait bound bloat / lack of inheritance
I'm trying to wrap the nalgebra and/or ndarray Rust crates into an abstract LinearOperator trait and corresponding AdjointableOperator etc. traits. The problem is that I get significant “trait bound bloat”, having to specify even internal…

497e0bdf29873
- 191
- 5
2
votes
1 answer
What is the most efficient way to read the first line of a file separately to the rest of the file?
I am trying to figure out the best way to read the contents of a file. The problem is that I need to read the first line separately, because I need that to be parsed as a usize which I need for the dimension of a Array2 by ndarray.
I tried the…

Martin Dagleish
- 133
- 6
2
votes
1 answer
How to generate a random stochastic matrix or ndarray?
I was looking for a crate that would allow me to easily and randomly generate probability vectors, stochastic matrices or, in general, ndarrays that are stochastic. For people not familiar with these concepts, a probability vector v is defined as…

nbro
- 15,395
- 32
- 113
- 196
2
votes
0 answers
Is there a more idiomatic way to do edge detection using ndarray?
Suppose I have an image represented as an Array2, for example:
const SIZE: usize = 8;
let image = Array2::from_elem((SIZE, SIZE), 0_u32);
I want to obtain an Array2 that has true in all locations where at least one pixel (in a…

Thomas
- 174,939
- 50
- 355
- 478
2
votes
0 answers
Rust ndarray: how to pass a slice as pointer array (&[T]) to function and mutable pointer array (&mut [T])?
I have a 3-dimensional array Array3 of the ndarray crate, and I would like to pass a slice of it as an array (&[T]) to a function, but can't figure out how. I found slice() and as_slice() methods, among similar others, but they require the data to…

Sergio Cavaleiro Costa
- 529
- 1
- 4
- 15
2
votes
1 answer
Rust create non-contiguous vector for testing
I am using the ndarray::ArrayBase type, and for one of my unit tests I need to check whether or not a vector is contiguous in memory. I am using the .is_standard_layout() method to check this, so I just need a way to create vector for testing that…

stackoverflowing321
- 333
- 4
- 14
2
votes
1 answer
What's the most efficient: a reference to an ArrayBase or an ArrayView?
I'm doing improvement on a Rust codebase that uses the ndarray crate to manipulate arrays. I have one question I could not find an explicit answer in the documentation.
Is it more efficient to pass an instance of ArrayView as an argument to a…

RFTexas
- 280
- 4
- 7
1
vote
1 answer
Rust ndarray: Mutating axis_iters
I am trying to implement somewhat "batched" matrix multiplication in rust using ndarray. Therefore I am trying to combine some .axis_iters and especially update a "result"-tensors Axis-iters accordingly. For me a problem occurs already when trying…

ginger314
- 13
- 3
1
vote
1 answer
Rust get mutable reference to each element of an ndarray in parallel
I am working on a parallel matrix multiplication code in Rust, where I want to compute every element of the product in parallel. I use ndarrays to store my data. Thus, my code would be something alone the lines
fn mul(lhs: &Array2, rhs:…

stomfaig
- 15
- 4
1
vote
1 answer
How to remove element from 2D array in Rust
I need help making sense of Rust's ndarray remove_index() function. For example, I have a 3x3 two dimensional array:
use ndarray::{arr2};
let mut arr = arr2([1, 2, 3],
[4, 5, 6],
[7, 8, 9]);
I would like to…

mabalenk
- 887
- 1
- 8
- 17
1
vote
1 answer
What does "v" stand for in ndarray (de)serialize?
I am trying to understand the "v" in ndarray (de)serialize:
use ndarray::prelude::*;
pub fn example() {
let ar2 = arr2(&[[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.]]);
let s =…

Anatoly Bugakov
- 772
- 1
- 7
- 18