In numpy, one can do
>>> np.linspace([1,2,3], [4,5,6], 4)
array([[1., 2., 3.],
[2., 3., 4.],
[3., 4., 5.],
[4., 5., 6.]])
However, it seems this isn't available from rust ndarray's linspace which only accepts Float.
How do I generalize rust-ndarray's linspace to accept 1D arrays (Array1<T>) of arbitrary size?
May not be optimized, but one way is the following
Basically,
assert!(start.len() == end.len());asserts same length(start.len(), n), (0..start.len()).map(|idx| Array::linspace(start[idx], end[idx], n))repeatedly callsArray::linspaceon each index which results in a nestedVec<Array<...>>.flatten().collect()flattens theVec<Array<...>>into a 1DVec<...>Array::from_shape_vec().unwrap()converts theVec<...>into a(start.len(), n)sizedArray(this is required since flatten arranges the elements as such).reversed_axes()transposes the array into shape(n, start.len())as is the case in numpy's linspaceThis passes the following test