Using the ndarray crate in rust.
I got a vector of array2 (which i know is not the best performance setup). I want to create a a Array3 from the this, but when I use from vector, or use the iter map, I only get Array1.
What would be the methode to flatten to Array3?
Related
I'm porting some scientific python code to Rust as a learning exercise. In the Python version, I make use of scipy.interp1d, which I'm using to do things like the following:
Given sorted array x and array y, calculate array new_y using new_x. (with some flexibility of algorithm, linear, cubic etc.).
https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d
Does anyone have nice Rust examples of this? I found the 'enterpolate' crate, but it seems mostly suited to interpolating to fixed interval x data. Is there anything in 'ndarray' that does interpolation?
I have an iterator of enum that has two variants. The iterator can be quite big, so I'd prefer to avoid iterating over it more than once. Is it possible to collect two vectors by iterating over it once?
Let's say I have a vector of numbers that are positive and negative. I'd like to kind-of sort them during iteration, which will result of two vectors - one with positive and other with negative numbers. Here's an example pseudocode:
let input = vec![1, -2, 4, -5, 3];
let (positive, negative) = input
.iter()
.some_magic_that_will_make_two_iterators()
.collect::<(Vec<_>, Vec<_>)>();
assert_eq!(positive, vec![1, 4, 3]);
assert_eq!(negative, vec![-2, -5])
Is there any way to achieve that? I know that I can define positive and negative first, and just push items during iterating, but that won't be the optimal solution for big collections. In my real case, I expect that there may be around million enums in the initial iterable.
Iterator::partition maybe?
It's eager so there is no collect step. It also can not map the elements when partitioning, so that might not work for your needs: it would work fine for partitioning positive and negative values, but it would not work to partition and unwrap two variants of an enum.
Is there any way to achieve that? I know that I can define positive and negative first, and just push items during iterating, but that won't be the optimal solution for big collections. In my real case, I expect that there may be around million enums in the initial iterable.
I don't see why not, it's pretty much what a partition function will do. And you might be able to size the target collections based on your understanding of the distribution, whereas a partition function would not be.
My xarray Dataset has three dimensions,
x,y,t
and 2 variables,
foo, bar
I would like to apply function baz() on every x, y coordinate pair's time series t
baz() will accept an array of foo-s and and array of bar-s for a given (x, y)
I'm having a tough time understanding whether or not built in structures to handle/distribute this exists in either, xarray, pandas, numpy, or dask.
Any hints?
My current approach is writing a python array iterator, or exploring ufunc:
The issues with iterating over something in python is that I have to deal with concurrency myself and that there is overhead in the iteration.
The issues with ufunc is that I don't understand it enough and seems like it's a function that is applied to individual elements of the array, not subsets along axes.
The hopeful part of me is looking for something that is xarray native or daskable.
Sounds (vaguely) like you are looking for Dataset.reduce:
ds.reduce(baz, dim=('x', 'y'))
What is the cleanest way to turn a Vector of vectors of unboxed doubles into a repa Array U DIM2 Double?
The most obvious way is to concatenate all the unboxed vectors into one and pass it to fromUnboxed, but that feels a bit clumsy. Is there a better alternative?
I have 3-dimensional tensor ("tensor3" -- an array of matrices), and I'd like to compute the determinant (theano.sandbox.linalg.det) of each matrix. Is there a way to compute each determinant without using theano.scan? When I try calling det directly on the tensor I get the error
3-dimensional array given. Array must be two-dimensional.
But I read that scan is slow and doesn't parallelize well, and that one should use only tensor operations if possible. Is that so? Can I avoid using scan in this case?
I see 3 possibilities:
If you know before compiling the Theano function the number of matrix in the tensor3 variable, you could use the split() op or just call det() on all matrix in the tensor3.
If you don't know the shape, you can make your own op, that will loop over the input and call the numpy fct. See for an example on how to make an op.
Use scan. It is easy to use it for this case. See this example, just change the call from tensordot to det().