Questions tagged [rust-ndarray]
54 questions
1
vote
1 answer
Converting an Array2 to Polar Coordinates
I am struggling to convert an Array2 of Cartesian Coordinates to Polar Coordinates. The two columns of each row have to be mutated based on each others values, and I can't figure out how to make it.
After different trials, I implemented the…

Gorka
- 1,971
- 1
- 13
- 28
1
vote
0 answers
Rust Ndarray Slice from vec/list of integers
I need to take a slice from ArrayBase ( ndarray crate ) with particular indexes (ie not range, not a single integer, but a collection of integers).
Example:
let ar = arr2(&[[1.,2.,3., 4.,5.,6.], [7., 8., 9., 10., 11., 12.]]);
From:…

Anatoly Bugakov
- 772
- 1
- 7
- 18
1
vote
1 answer
How to compare shapes of ndarrays in a concise way?
I'm new to Rust.
Suppose a matrix a has shape (n1, n2), b has (m1, m2), and c has (k1, k2). I would like to check that a and b can be multiplied (as matrices) and the shape of a * b is equal to c. In other words, (n2 == m1) && (n1 == k1) && (m2 ==…

ywat
- 2,757
- 5
- 24
- 32
1
vote
0 answers
Why is returning a cloned ndarray throwing an overflow error(exceeded max recursion limit)?
I'm currently trying to write a function that is generally equivalent to numpy's tile. Currently each time I try to return a (altered or unaltered) clone of the input array, I get a warning about an overflow, and cargo prompts me to increase the…

Joshua Ferguson
- 43
- 1
- 5
1
vote
1 answer
get diff of 1d rust ndarray
I feel like this code should work:
use ndarray::{Array1, s}; // 0.15.4
fn main() {
let x = Array1::::range(0.0, 10.0, 1.0);
println!("{:?}", x);
println!("{:?}", x.slice(s![1..]));
println!("{:?}", x.slice(s![..-1]));
…

Chad
- 1,434
- 1
- 15
- 30
1
vote
1 answer
How to wrap function with NDArray input and output with PyO3?
I want to wrap a function that takes an one-dimensional NDArray (rust-numpy) and an usize as parameters, and returns a one-dimensional array using PyO3 to call the code from python. Unfortunately, I can't find a good example of how to deal with the…

0xSingularity
- 577
- 6
- 36
1
vote
1 answer
Rust ndarray mismatched types
I'm trying to get an Array3 from an image using ndarray_image:
pub fn from_png(path: &str) -> Result {
return match ndarray_image::open_image(path, Colors::Rgba) {
Ok(data) => { ;
let size = Size {
…

dath.vg
- 86
- 1
- 7
1
vote
1 answer
`AsArray` cannot be made into an object when implementing a trait for a trait
Basically I'm trying to make a trait that indicates the ability to be converted into a 2D ndarray aka ndarray::Array2:
trait Into2DArray{
fn to_array(&self) -> Array2;
}
I would like to do this by expanding the existing AsArray trait, but…

Migwell
- 18,631
- 21
- 91
- 160
0
votes
1 answer
Can the rust compiler optimize Array2 better when the shape (size) is known at compile time?
I'm using Array2 or Array1 in rust for matrices in a neural network. (Yes, I know there are libraries for NNs. I want to do it with my own code for learning. The question stands independently of the neural networks, but neural networks serve as a…

Daniel S.
- 6,458
- 4
- 35
- 78
0
votes
2 answers
How to convert a Vec to a ndarray
I'm starting to learn rust, so let me know if there is a more proper way I should be approaching this problem, but I'm looking for similar performance of numpy from python when doing element wise operations on vectors. It looks like the ndarray…

Dak
- 19
- 5
0
votes
0 answers
Optimizing memory allocation for ndarray code in Rust
I'm trying to write optimized code to do this:
a = x^2
b = x^2 sin(e^x)
c = x^2 cos(e^x)
Code:
let mut x = arr1(&[1.0, 2.0, 3.0]);
let x2 = &x.mapv(|v| v*v);
let a = x2.view();
x.mapv_inplace(|v| (v.exp()));
let b = x2 * &x.mapv(|v|…

HAL
- 381
- 1
- 2
- 13
0
votes
0 answers
How to create Rust ndarray with custom explicit indices
Is it possible in Rust to create and initialise a 3D array (ndarray) with explicit indices? As I understand, by default Rust creates an array with zero-based indexing:
use ndarray::Array3;
...
const NX: usize = 100;
const NY: usize = 100;
const NZ:…

mabalenk
- 887
- 1
- 8
- 17
0
votes
1 answer
Can I reshape a non-contiguous view in rust-ndarray?
This program compiles, but panics at run time with the message below. (playground)
use ndarray::prelude::*;
fn main() {
let a = Array2::::zeros([100, 10]);
let b = a.slice(s![5..15, ..8]);
let c = b.into_shape((10, 2,…

Jason Orendorff
- 42,793
- 6
- 62
- 96
0
votes
1 answer
rust ndarray cumulative product/sum
I am learning the rust language and working with the ndarray crate. Could someone explain to me how to apply cumulative functions to an ndarray?
As example it would be great to see how to get a cumulative product of an ndarray.
I could not manage to…

Jost
- 77
- 6
0
votes
1 answer
How to transform a tiff file to ndarray in rust?
I would like to create an ndarray in Rust containing data from a Tif image.
I'm new to rust so it might be a silly question.
I using this code:
let file = std::fs::File::open("some_image.tif").unwrap();
let mut decoder =…

yif tach
- 1