前提・実現したいこと
rust_ndarray
を用いて、Array2
の任意の場所の要素で全体のArrayを引き算したいと考えております。
pythonでは、
python
1a = np.array([[1.,1.,], [3.,4.,], [4.,4.,]]) 2new_a = a - a[0] 3// new_a => np.array([[0.,0.,], [2.,3.,],[3.,3.,]])
のような計算を行いたいと考えております。
発生している問題・エラーメッセージ
error[E0277]: the trait bound `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>: ScalarOperand` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `ScalarOperand` is not implemented for `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>` | = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0277]: the trait bound `ViewRepr<&f64>: DataOwned` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `DataOwned` is not implemented for `ViewRepr<&f64>` | = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0277]: the trait bound `ViewRepr<&f64>: DataMut` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `DataMut` is not implemented for `ViewRepr<&f64>` | = help: the following implementations were found: <ViewRepr<&'a mut A> as DataMut> = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error: aborting due to 4 previous errors; 1 warning emitted error[E0271]: type mismatch resolving `<f64 as Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>>::Output == f64` --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ expected struct `ArrayBase`, found `f64` | = note: expected struct `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>` found type `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0271]: type mismatch resolving `<f64 as Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>>::Output == f64` --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ expected struct `ArrayBase`, found `f64` | = note: expected struct `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>` found type `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0277]: the trait bound `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>: ScalarOperand` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `ScalarOperand` is not implemented for `ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>` | = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0277]: the trait bound `ViewRepr<&f64>: DataOwned` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `DataOwned` is not implemented for `ViewRepr<&f64>` | = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error[E0277]: the trait bound `ViewRepr<&f64>: DataMut` is not satisfied --> src/features.rs:17:15 | 17 | let c = c - c.slice(s![idx, ..]); | ^ the trait `DataMut` is not implemented for `ViewRepr<&f64>` | = help: the following implementations were found: <ViewRepr<&'a mut A> as DataMut> = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `f64` = note: required because of the requirements on the impl of `Sub<ArrayBase<ViewRepr<&f64>, Dim<[usize; 1]>>>` for `&ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>` error: aborting due to 4 previous errors; 1 warning emitted Some errors have detailed explanations: E0271, E0277. For more information about an error, try `rustc --explain E0271`.
該当のソースコード
rust
1// c: &Array2<f64> 2 3let c = c - c.slice(s![idx,..]);
できれば、c
などをclone()
せずに行いたいと思います。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。