-
Notifications
You must be signed in to change notification settings - Fork 326
Could not broadcast array from shape: [2] to: [2, 1] #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That's right. The |
By the way, you can use subview mut or the method |
I'd do this a.column_mut(0).assign(&aview1(&u));
a.column_mut(1).assign(&aview1(&u)); Creating an array view from the Edited: Fixed method name, it's column_mut. |
co-broadcasting (issue #11) does not apply here, so there is no intention to fix this; it works as designed. Co broadcasting applies when we can allocate a new result, for example something like this dimensional equation, where the result doesn't have the shape of either operand.
Today only shape preserving of the left hand side is allowed, for example:
|
I think this is a related issue. I'm trying this code: extern crate ndarray;
use ndarray::prelude::*;
fn main() {
let x = Array::linspace(0.5, 1.5, 5);
let y = arr2(&[[0.1, 0.2, 0.3]]);
let z = y + x;
} But it fails with
I would have expected this to work as it does in numpy:
Any suggestions for how I can do this the right way here? |
numpy has implemented broadcasting a step further than we have. (Some kind of co-broadcasting where both sides are adjusted). It would do fine as a feature request issue. |
Using slices, I want to set the columns or rows of the
2×2
matrix (i.e.Array
)a
to the vectorsu
orv
, respectively. This works when slicing along the first axis (getting row-slices), but not along the second:I suppose the problem is that
ndarray
can broadcast from[2]
to[1,2]
, but not to the reverse.The text was updated successfully, but these errors were encountered: