Skip to content

Any possibility to add assign arr0s to scalars? #1139

Answered by frjnn
frjnn asked this question in Q&A
Discussion options

You must be logged in to vote

Something like this.

fn main() {
    let mut scalar: f32 = 2.0;

    let zero_dim = ndarray::arr0(3.0);
    scalar += &zero_dim;

    println!("{}", scalar);
}

Out

   Compiling playground v0.0.1 (/playground)
error[E0277]: cannot add-assign `&ArrayBase<OwnedRepr<{float}>, Dim<[usize; 0]>>` to `f32`
 --> src/main.rs:5:12
  |
5 |     scalar += &zero_dim;
  |            ^^ no implementation for `f32 += &ArrayBase<OwnedRepr<{float}>, Dim<[usize; 0]>>`
  |
  = help: the trait `AddAssign<&ArrayBase<OwnedRepr<{float}>, Dim<[usize; 0]>>>` is not implemented for `f32`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

P…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@frjnn
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@adamreichold
Comment options

@frjnn
Comment options

@bluss
Comment options

@frjnn
Comment options

Answer selected by frjnn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants