« first day (1871 days earlier)      last day (1347 days later) » 

3:59 AM
@AndrasDeak The data comes from a different person, and I have no control over the format they use.
@AndrasDeak So if I have an array (in this case: 0:23), reshape(2,3,4) will give me 2 pages of 3x4 matrices. That doesn't really solve the problem of turning a 2x2xN list of numbers in a file, into a 2x2xN array in memory.
Sorry that I took long to reply, I got pulled away from the computer for a few hours and only got back now!
 
 
5 hours later…
8:49 AM
@user1271772 it wouldn't be much of a tease to show you a similar reshape approach in another language, would it?
>>> np.array([[[ 0,  1,  2,  3],
...         [ 4,  5,  6,  7],
...         [ 8,  9, 10, 11]],
...
...        [[12, 13, 14, 15],
...         [16, 17, 18, 19],
...         [20, 21, 22, 23]]]).shape
(2, 3, 4)
 
 
3 hours later…
Sam
11:47 AM
@flawr In a very horrid way. :p
 
 
2 hours later…
2:09 PM
LOL “You can do it even faster, without a loop” @Adriaan
Your typical “this is what you asked for, but this is what you want” answer!
 
2:22 PM
hi,
folks with >=R2018b, can you please check for me if any(xy,'all') for a 3D array gives a 1x1 array or checks for each slice separately?
 
2:51 PM
the doc of any says that it tests over all elements. BUT as per the release notes (release notes give the example for sum though), any(A,'all') is equivalent to any(A,[1 2])which is why I am asking that
 
3:04 PM
I like that! So numpy allows people to build a multidimensional array in a more "natural" way by adding more square brackets. That is essentially what { } does in MATLAB (cell arrays). [This MATLAB solution](https://chat.stackoverflow.com/transcript/message/50206143#50206143) by @LuisMendo is still nicer though because it doesn't need the ugly `np.array( )` and the commas between each number, and the extra [ ] around each row.

I still do appreciate that `cat` is not needed, so someone that knows only basic numpy can do this, whereas in MATLAB someone would have to know about `cat` or look
 
just noticed that you can now view docs of previous releases without signing in with your licensed account. It wasn't allowed before. iirc
 
3:40 PM
@SardarUsama It works over all dimensions, yields a scalar. "any(A,'all') is equivalent to any(A,[1 2])", but only if A is 2D.
 
@CrisLuengo that's what I doubted. The wording in the release notes should have been better/clearer. Thanks for testing
 
Release notes often simplify things a bit too much.
 
the doc also doesn't have any example for any(A,'all') :/
 
It does for sum: mathworks.com/help/matlab/ref/… (see the bottom of this section, which compares sum(A,[1 2 3]) to sum(A,'all') for a 3D array.
 
hmmm..
 
3:47 PM
I like that they've added "This syntax is valid for MATLAB® versions R2018b and later." to the docs. Too many changes are not tagged like this, making it hard to know when changes were introduced without searching through the release notes.
 
@CrisLuengo thanks again for the recommendation, I read quite a bit about them - while they are not conformal (would have been too easy:) they still have some very nice properties!
 
3:59 PM
This question is all messed up. The OP gave an example of a 3D array; mentioned multidimensional array in the question title. (the OP actually had much more dimensions). @Adriaan edited multidimensional to 3D array. Now the 3D array solutions that work on the original mcve don't work on OP's edited in actual data. Not sure what to do here.
 
@SardarUsama Wording could be better, but it says (emphasis mine) For example, sum(A,'all') sums all the elements in a matrix A, and is equivalent to sum(A,[1 2]).
 
yes but then it says equivalent to sum(A,[1 2]) :/
 
But that should be understood to be a continuation of "in a matrix A"
Not the clearest wording, granted
 
@LuisMendo so if I understand correctly, you mean that for >2 dimensions, we use the word "array" only and not "matrix". So is there no such thing as a 3D matrix?
 
Yes, "matrix" implies 2D only
 
4:13 PM
Thanks @LuisMendo for the clarification. I am sure I must have been wrongly/interchangeably using these words before for a 3D array atleast.
 
Anytime!
 
 
2 hours later…
5:55 PM
@SardarUsama well, OP had a 3D array.
I assumed, given the MCVE, that they were pages, i.e. 2D matrices, in a 3D array. I rolled back the edits
When cycling home I was still brainstorming about this one, and indeed thought about any and all, with any being faster due to the possible early termination
 
both terminate early :P
 
6:25 PM
@Adriaan i would have assumed the same. Not your fault
 

« first day (1871 days earlier)      last day (1347 days later) »