Skip to content

Instantly share code, notes, and snippets.

@phasetr
Created April 2, 2020 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phasetr/46f07a835c4ab01000cf33e537114579 to your computer and use it in GitHub Desktop.
Save phasetr/46f07a835c4ab01000cf33e537114579 to your computer and use it in GitHub Desktop.
rust ndarray
// cargo-deps: serde, serde_derive, serde_yaml, ndarray
extern crate ndarray;
extern crate serde;
use ndarray::array;
use ndarray::prelude::*;
use ndarray::Array;
use ndarray::Array1;
fn main() {
let arr1: Array1<f64> = array![1.0, 2.0, 3.0, 4.0];
let arr2: Array1<f64> = array![5.0, 6.0, 7.0, 8.0];
let mut arr_sum1: Array1<f64> = Array::zeros(4);
println!("{}", &arr_sum1);
arr_sum1.slice(s![0..2]) = &arr1.slice(s![1..3]) + &arr2.slice(s![2..4]);
}
@phasetr
Copy link
Author

phasetr commented Apr 2, 2020

出てくるエラーは次の通り。

error[E0308]: mismatched types
--> code_check.rs:28:32
|
28 | arr_sum1.slice(s![0..2]) = &arr1.slice(s![1..3]) + &arr2.slice(s![2..4]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct ndarray::ViewRepr, found struct ndarray::OwnedRepr
|
= note: expected struct ndarray::ArrayBase<ndarray::ViewRepr<&f64>, _>
found struct ndarray::ArrayBase<ndarray::OwnedRepr<f64>, _>

error[E0070]: invalid left-hand side expression
--> code_check.rs:28:5
|
28 | arr_sum1.slice(s![0..2]) = &arr1.slice(s![1..3]) + &arr2.slice(s![2..4]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment