« first day (1870 days earlier)      last day (1359 days later) » 

7:27 AM
 
8:03 AM
I like how so many posts on "how to implement algorithmX" use from scipy.* import algorithmX
 
 
5 hours later…
1:18 PM
@flawr well it's the right answer in the vast majority of cases
 
1:29 PM
it might be the right answer, but not to the question asked:)
it's like if you're primising to explain "how to add 1 + 2", and then proceed to say "use a calculator"
this just means it is impossible to ask how to implement something if you actually want to know how you implement it
 
@flawr impossible to ask on Stack Overflow where there's probably already a duplicate. And there are a lot of resources off-site already that tell you how to implement things
which is not to say that some people might not have a good reason to ask about the actual implementation, which is why I said "in the vast majority of cases"
 
sure tha tis what I understood, I was just a little bit pissed off by this usage of the term, when they don't actually mean what they say:)
(and it then makes things more difficult if you actually want to know that)
 
Controversial take: any proper question with "how to implement" should be
 
I'd immediately sign this petition!
You could argue though that sometimes certain implementations are better suited for a certain language than others and vice versa.
 
1:45 PM
"jQuery has a plugin for that!"
 
haha yes:)
 
Sam
2:06 PM
@AndrasDeak Can I pick your brains. Its a torch snippet but I think theres a lot of overlap with NumPy on operation
torch.zeros_like(e).scatter(0,idxs.unsqueeze(1).unsqueeze(1).expand(-1,e.size(1),e.size(2)), e)
This is essentially re-ordering along the 0 axis right? Where idxs is a integer vector of positions
 
the unsqueeze(1).unsqueeze(1) seems to be completely unnecessary
i'd put that into expand() to make it more readable
(and I prefer an explicit array[:, None, ...] any day over unsqueeze(1))
(sorry no it is not unnecessary, but you can use a single command with the indexing notation)
but yes it seems to mangle axis 0
sorry @AndrasDeak I don't want to put you out of work:P
 
2:21 PM
Oh no, by all means. Sam, let me know if I should still read the question :P
I was distracted by
in SO Close Vote Reviewers, 3 hours ago, by oguz ismail
There's this test that does a good job guessing your native language, I didn't know it was so obvious that my first language is Turkish
@Sam ping because flawr didn't ping you, just to be sure. In any case I don't know what .scatter does and I only suspected what unsqueeze does. Don't know what expand does. Too far from the numpy API.
 
@AndrasDeak and, do you speak US Vernacular/Ebonics as well? :P
 
> Our top three guesses for your English dialect:
1. Singaporean
2. Australian
3. English (England)
Our top three guesses for your native (first) language:
1. Italian
2. Romanian
3. Vietnamese
 
:D
 
and later it said "Singaporean is very similar to Standard American English and the two can be hard to distinguish."
 
@AndrasDeak the pictures are hilarious :D
 
2:25 PM
not very close :)
@flawr yes :D
 
@Sam if you have questions about pytorch feel free to ping me, I used it quite a bit in the past year!
 
I should troll questions by posting python answers and calling it pseudocode
 
better that way than the other way around:)
maybe include some obscure syntax error for fun:)
Our top three guesses for your English dialect:
1. US Black Vernacular / Ebonics
2. Singaporean
3. American (Standard)
Our top three guesses for your native (first) language:
1. German
2. Finnish
3. Italian
 
2:43 PM
not bad
 
The 3 words of finnish that I know must really have a big effect:)
vittu, saatana, perkele!
 
lol
you should also learn kalsarikännit
 
google say "underweardrunk" !?!?
 
Yes, the mood in which you get drunk at home in your underwear
 
3:10 PM
why did I think of homer simpson? :P
 
Sam
3:47 PM
I get what its doing now, its just doing a resort along a dimension. But that code is absolutely disgusting. scatter seems like a useful function to me
It took me a few hours to realise what the scatter actually does. But thanks both. Hope you are all well. :)
 
No worries; and yeah, all good, thanks. You?
 
Sam
Yeah all good thanks. First day back in the office today.
 
ah, exciting
 
Sam
Only for today though. White board session. Going through some open source code which is an absolute mess
 
 
5 hours later…
9:30 PM
Hi everyone. I am considering to ask a MATLAB question, however it has been ages and ages since I asked a question on SO and I am scared.
 
why scared?
 
9:51 PM
@flawr My understanding is that SO has changed a lot since I started using it.
 
maybe, but what's the worst that could happen when writing a question
 
being downvoted to hell is the usual fear ;)
 
@AndrasDeak Exactly. I spend quite a lot of time on my questions, and it's just not fun if it gets 10 downvotes and closed, then deleted.
Also now that there exists MATLAB Answers, I don't know how well received MATLAB questions would be on SO. It seems to have become more of a Python/JavaScript/Java/PHP haven.
 
the various tags have pretty different cultures
 
If you spend some time on your question you rarely get downvoted, I mean the downvotes are usually for dupes or questions with no MCVE, an that covers about 99% of the downvoted matlab questions.
 
10:04 PM
even within python, and are dumpster fires compared to some other python tags
 
@user1271772 so why don't you post it - I promise to upvote if you're at -9 votes to prevent it from reaching -10?
 
MCVE is some sort of Minimum Working Example I guess?
minimum complete verifiable example
My questions were reasonably well received over the years, until my last one (in 2016) about Python:
 
just don't worry too much:)
 
As someone that was used to MATLAB for 10 years and never touched Python, it was hard for me to grapple with the fact that I couldn't just call a function as simply as I can in MATLAB, but I did put a lot of effort into that question and searched for an answer myself (both on SO and outside of SO), then posted 2 examples of things I read from SO and 2 examples I read from outside of SO (all 4 did not answer the question).
 
@user1271772 well, 2016 was long ago too, and I don't know how your question would be received today. But questions asking to solve problems that can be replaced with reading a tutorial are often badly received (and answered by rep farmers anyway). In particular, your own "command line parsing" link showed how to do what you needed.
Does MATLAB even support calling functions like that with command line args?
 
10:22 PM
By the way the "command line parsing" question is not very specific, didn't show any example code, and posted the same number of links as me (so they might have spent the same amount of time doing research), but it has 637 more upvotes than downvotes. I was highly unsatisfied with the answers because they all required "importing" of external packages like "from argparse import ArgumentParser".

For that reason I felt I should write a question that is more specific about what I want to do.
 
And the question you had in mind now links to the argparse docs. Python docs always has examples, I'm sure that has too.
 
@AndrasDeak These links are some rather large tutorials that have so much import this and import that, which causes my head to glaze over because I know zero python. I do not remember having such a difficult time getting started with MATLAB.
 
spending some time learning some basics is inevitable whenever you're facing new technology
That's where good tutorials can help, by structuring the new stuff. If you already know programming then python's official tutorial isn't too bad
random crap written by random idiots are too many these days...
 
Our top three guesses for your native (first) language:

1. English
2. Norwegian
3. Swedish
 
nice
 
10:33 PM
Damn Swedes! They changed my language! :)
 
@AndrasDeak I guess you use Python a decent amount?
 
@user1271772 yup
 
Since when?
 
let me see
5 years
 
I suppose after that long, you might no longer be able to appreciate how things look from my angle. I guess that was the case with all the other people that saw the question too.
@AndrasDeak @flawr Here is my MATLAB question, which I'm not sure whether or not to post on SO:
I could alternatively post it on "MATLAB Answers" if it would not be well received on SO. I just happen to have invested a lot into the SO Network over the years, so it would be nice to be able to post here.
 
10:45 PM
I don't see how that question would be downvoted. Of course there's always the random unexplainable downvote. But it's not a bad question IMO.
 
@user1271772 5 years ago wasn't that long ago. And I came from MATLAB arguably I was in a similar situation.
then again I'm aware that my learning patterns are not universal to all humans
 
@CrisLuengo Now that I've spent all the time writing the question anyway, I might as well post it. I suppose that at the beginning when I first came here asking for advice, I was not only worried about downvoting, but more so the possibility that I would spend a lot of energy writing the question and then not get any answers because it's "off-topic" or SO has become a Python/Java haven or something.
 
@user1271772 it's unclear to me what your data really is. Is it (say) a hundred arrays? Or a text file in the format of the first block?
 
@AndrasDeak Its a text file in the format of the first block
 
@user1271772 that last bit is a highly irrational fear :P
 
10:50 PM
@AndrasDeak Why is it irrational?
 
Nah, post with the right tags, and the python people won't even see your question. There's so many questions posted here, that people only look at questions within a few of their favourite tags.
 
@user1271772 I'd make that explicit to make it clear
@user1271772 because obviously SO is chock full of all sorts of questions, even looking at fresh questions
 
@AndrasDeak Thank you for the advice, I'll make it clear that the first block is a text file.
 
and help/on-topic hasn't changed much
 
@AndrasDeak The fact that millions of people ask questions all the time, doesn't mean I shouldn't try to spend my time/energy wisely (i.e. only spending the energy to write something, if it's actually going to lead to something, such as a good answer).
 
10:53 PM
Well SO is going down so arguably spending your time here is a questionable investment :) But odds are looking up for askers
@user1271772 it's also not very clear what I gathered from the question: that you don't have a programmatic approach, but you're rather trying to copy-paste the contents of the file (or a modified version thereof) into the matlab command window. Is this correct?
 
@AndrasDeak What do you mean by "SO is going down" ?
 
The site is drowning in low-quality questions posted by people who expect others to do all their work for them, and the company running the site has forgotten what it was built on and is sidelining the community, regularly causing huge damage all for hopes of more profit.
 
@AndrasDeak I'm not sure what exactly "programmatic approach" means, but the data is not generated by computations (or some program). It is given to me in a file. So yes: I am either importing it using load or import or copying and pasting into a command window.
 
@user1271772 no, I was specifically talking about your parsing
 
@AndrasDeak I see. The site is staying up though?
 
10:56 PM
@user1271772 for the time being
but many veterans have become inactive or left, and the ones remaining don't have very positive expectations
@user1271772 For instance: what if you could wrangle your data to be in the "ideal" format? How would you put the result into MATLAB?
 
What I called the "ideal" format is the format in the second block. Unfortunately copying and pasting that into the editor (or command window) and running it, would just make a (2N x 2) array, which has to be reshaped into 2x2xN.
 
Yeah, so that's what I meant: that your main approach is copy-pasting, rather than using a script that will eventually load your data from the file (I wouldn't worry about the reshaping step because as you noted that's easy).
That's another thing that wasn't clear to me at first, and I can imagine people not understanding that or demanding your code (when you don't have much code yet)
 
I have made a preliminary attempt at a question, and I took your advice and added in the first sentence, that the data is coming from a "text file":
0
Q: Is there a way to stack multiple 2x2 matrices in MATLAB into a multidimensional array, without using "cat" or "reshape"?

user1271772I am receiving a text file with 1000 matrices of size 2x2 each day from someone, in the following format (only 3 matrices shown instead of 1000): 0.96875000 0.03125000 0.03125000 0.96875000 0.96875000 0.01562500 0.03125000 0.98437500 0.99218800 0.03125000 0.00781250 0.96875000 I need to mak...

 
But as I said tags are their own world and I haven't been active in for years. You can trust Cris's judgement.
Although the title of the question you just posted is misleading... it sounds like you have the matrices in memory. But maybe that's just me.
 
@AndrasDeak Why can I not trust Cris's judgement? He's one of the leaders in the tag!
 
11:12 PM
@user1271772 reread what I wrote? :P
 
oh hahaha!
I misread your comment :)
sorry about that
 
no worries
 
Our top three guesses for your English dialect:
1. New Zealandish
2. Australian
3. Singaporean
Our top three guesses for your native (first) language:
1. Romanian
2. Italian
3. English
This algorithm is a bit clueless :-)
Well, Italian is my third language, and pretty similar to Spanish...
 
It does say that native language guessing is still rudimentary
 
Ah. Indeed
@user1271772 I also miss a way to write 3D-array literals. But there isn't
 
11:20 PM
A shame, in a language with native n-dim arrays
unless n < 2 ;)
 
Hehe
 
@LuisMendo It seems that there would be no disadvantage to introducing a double-semi-colon, or interpreting an empty line between 2D matrices as going across a 3rd dimension.
 
@user1271772 except that the current parser is really forgiving
and undoing that would be grossly backward-incompatible
 
Well, double semicolon would break current syntax. [1;;2] works now (same as [1;2])
 
@CrisLuengo Do you have any advice on what might be the simplest way to do the permutation?
 
11:22 PM
some of the guys from here have questions/answers about hair-raising things like that ^^
@user1271772 permute(arr, 2, 1, 3), probably
 
@user1271772 I'm confused by the question you posted. Do you want to modify the file and eval it? Or read it sprintf style?
 
Or maybe another way around... I always check these in practice. And this is why I prefer non-square test cases.
 
There needs to be some square brackets in there I think @AndrasDeak
 
@user1271772 maybe :)
I mean either that or [2, 1, 3], yeah
 
@LuisMendo I kept it deliberately vague because I'm open to whatever is simplest.
 
11:25 PM
weird that reshape has varargs but permute doesn't
especially since reshape is a lot more likely to have dynamic number of elements, so the vararg syntax is much more likely^[citation needed] to be used by permute
 
permute(reshape(ideal,2,2,[]),[2,1,3]) and permute(ideal,[2,1,3]) don't work. I'm continuing to try other things.
@AndrasDeak I've edited to put the square brackets in.
 
I can see
So how "does [it] not work"?
 
It doesn't given an error, but it gives the wrong matrices
 
I think you want permute(reshape(x.', 2, 2, []), [2 1 3])
 
I think you will have to import it as a 2D array and then use reshape and permute to get it to where you need to be. Only reshape would create a 2x1000x2 array, if you initially read it in as a 2000x2 array. — Cris Luengo 23 mins ago
 
11:28 PM
[1,2,3] doesn't work either
 
it's your reshape that's off
 
where x is as in your second snippet in the question
 
If Cris is right, and we agreed to trust his judgement, you need reshape(x, 2, [], 2)
 
@LuisMendo Yes!
 
The first two 2's are the matrix size
 
11:29 PM
but that seems to contradict Luis' version
 
@AndrasDeak This makes 2 rectangular matrices rather than 3 squares :)
 
that's what you need permute for...
@LuisMendo I'm pretty sure it could be done without the transpose, by rearranging the reshape and the permute indices
 
Luis's version does give the correct matrices, and Andras might be correct that it's possible to simplify it.
Now I play "code golf" with what Luis gave.
 
if I had to guess I'd just reverse it all: permute(reshape(x, [], 2, 2), [2, 3, 1])
 
Hm I don't see how to avoid the transpose. You need to traverse the second dim first, so you need to move it to the first dim, that is, transpose
 
11:32 PM
@LuisMendo then you're probably right; it's been too long since I MATLABbed
 
The fact that we need to do permute(reshape(ideal.', 2, 2, []), [2 1 3]) is unsatisfying to me. I see no disadvantage of there being a way to read data directly into 3D arrays, or to type 3D arrays from 2D components without using cat
 
@user1271772 that's a bit like an "I don't like rain so I'm on strike until it stops raining" argument. MATLAB doesn't have syntax for defining 3d arrays. You can only work around it.
just pick up an umbrella :)
 
@AndrasDeak I don't disagree with that. The issue of stacking two matrices on top of each other is so simple though, that I'm sure many people would also wonder if there's a simpler solution!
 
(technically both reshape+permute and cat are umbrellas)
@user1271772 reshaping a 2d array into 3d is stacking two matrices on top :)
 
You could also use cell arrays. But those are less efficient. And in your case it requires addint more symbols the file, not just at the beginning and end
x = {[0.96875000 0.03125000
0.03125000 0.96875000];

[0.96875000 0.01562500
0.03125000 0.98437500];

[0.99218800 0.03125000
0.00781250 0.96875000]}

result = cat(3, x{:})
 
11:39 PM
@AndrasDeak However permute is required, even though the human eye can stack the matrices much more directly.
@LuisMendo Nice! This is getting close to what I came to SO for!
 
Huh? I still don't get what you prefer. Just less characters?
*fewer
 
Well, the text file that I'm receiving, is already written in the format:

`Matrix`

`Matrix`

`Matrix`
I might use the reshape + permute solution, but it required a lot of thinking and experimenting (for me at least... I have been away from MATLAB and all types of programming for several years... in fact it's probably been 8-9 years since I did serious coding in MATLAB).
 
octave:48> arr = reshape(1:2*3*4, [2*3, 4]);
octave:49> luis = permute(reshape(arr.', 4, 2, []), [2, 1, 3]);
octave:50> andras = permute(reshape(arr, 2, [], 4), [1, 3, 2]);
octave:51> all((luis == andras)(:))
ans = 1
(octave cheat for one-line multidim all :P)
 
Hey! So you got rid of the transpose?
 
yup
my original was wrong, but it was possible (as I just assumed)
 
11:45 PM
Oh, maybe you're wondering why I like your solution more than my cat solution? It's because the line-breaks/white-spaces between the lines, is prettier, in my opinion. I can "see" the original matrices easier.
Nice solution @AndrasDeak! But the amount of time it took us to get there, is exactly why I think MATLAB should provide a new type of umbrella!
 
I know a language where this would be really easy, nudge nudge wink wink
 
Python?
 
with numpy, yes
 
How would it be done in numpy?
 
Nested square brackets lead to multidimensional arrays there. That being said, defining 3d arrays by hand is a bad idea.
 
11:48 PM
@AndrasDeak I see now. Well done!
 
So actually with numpy I'd still just read in the multiple 2d arrays or one long 2d array and reshape it :P
and the "reading in" would be a bit worse in numpy because numpy's data loaders are less forgiving than that of MATLAB, so those empty lines might lead to trouble
 
My question is about what's the easiest way to generate a 3D array like this by hand though
 
You can't really generate 3D arrays by hand in Matlab, I mean as literals. You need this type of tricks
 
these types of tricks yea
The permute+reshape solution was not so simple, and the "cat" solution is ugly.
yes generating a 3D array is such a simple thing though.
I wonder if Julia has a better solution?
 
I'm also wondering: where do all these matrices come from? Ideally you'd create a 3d array at the start, and not print out a broken collection of 2d arrays.
a 3d array in memory is a well-defined animal, and passing them to and from between computers would be simpler with mat files
but just to tease you:
>>> np.arange(2*3*4).reshape(2, 3, 4)
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]]])
(you can see 2 3x4 arrays because numpy uses row-major memory layout so it reads everything backwards as compared to MATLAB's conventions)
 
11:56 PM
I'm off for today! G'night / whatever!
 
Night, Luis. Same here soon :)
 

« first day (1870 days earlier)      last day (1359 days later) »