-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
array assignment a[1,:,:] = b fails even when b is the correct size #4048
Comments
Having array dimensions change on you simply because you index them with scalars rather than a range is a formula for lots of trouble. What you're looking for is
You can assign to your sliced array:
|
I think there are already cases where case that array dimensions change based on whether you index them with a scalar or a range.
Although maybe there is a good reason to see this differently since it is going down to a single element? But really I think input on what size arrays returned from thing should be is beyond me since I'm so new to julia. Regardless, perhaps something like broadcasting could be used to allow assignment between arrays that differ only by singleton dimensions? |
Personally I feel like a[1,:] = b Shouldn't work, but a[1,:,:] = b should, because it's weird to put a 2D object into a 1D space (by doing an implicit reshape), it just doesn't fit in there. The second one makes much more sense, because you have a stack of matrices and you simply put your matrix somewhere in the stack. |
I agree with @Staross |
Let A has a size n x n x n, I feel that A[1,:,:] should have a size n x n, while A[1:1,:,:] should have a size 1 x n x n. This is much more consistent and uniform (since 1:1 is a range while 1 is not a range). Currently, A[1,:,:] has a size 1 x n x n in Julia. This is not intuitive and is inconsistent (since A[1,1,1] is a scaler not a 1 x 1 x 1 Array). |
Yes, assignment between arrays that differ only by singleton dimensions would make the design choice to keep those singleton dimensions in subscripted arrays friendlier. This extension would be still conservative I think: a.) The assignment
considers a 1-dimensional array as data without any shape already now and b.)
is allowed as well. Therefore
|
Julia Studio 0.3.2
For comparison this works in both MATLAB and numpy.
python + numpy
Personally I feel it makes more sense to have the resulting array from a[1,:,:] have size (9,9) rather than (1,9,9). I also know that in MATLAB the leading singleton dimensions make plot fail where it would work with a 2d array, which is often annoying.
MATLAB
Here is a more extreme case, where I can't find any solution that works.
All of the equivalent "extreme case" assignments do something in numpy. In MATLAB both of the unambiguous assignments (a[1,1,:,:]=b and a[1,:,:,1] = b) work, and the others do not.
I'm new to julia, so I'm not sure if you want the more ambiguous of these to work. For example its ambiguous in the "extreme case" what a[1,:,1] = b even means. But certainly the unambiguous subset of these assignments should work.
Also I don't know about the implementation, but from a user point of view this is similar to issue #4033
The text was updated successfully, but these errors were encountered: