« first day (723 days earlier)      last day (2506 days later) » 

12:00 AM
I added an almost-pure-numpy answer, it's pretty bulky but it doesn't really cheat anywhere
the answer I left the comment on will be much shorter with my suggestion, no way to outgolf that without eval or native python magic, I think
 
12:18 AM
WTF SO!?!?!?! ^
 
@AndrasDeak He's using the double-sided Laplace Transform ... not a fan.
 
me neither
@WarrenWeckesser Hmmm.... That sounds like a possible bug. Let me double check that's working correctly. — Hynes ♦ 36 mins ago
^ i.e. that job spam is shown to people who ignore Jobs entirely
 
 
9 hours later…
8:53 AM
@AndrasDeak Nice improvement! So when you index with multiple indices in Numpy there's an "implicit sub2ind" (in Matlab terms), right? I would have expected that indexing to produce the whole n-D array, not its hyper-diagonal
So how would you extract a submatrix in Numpy? Like Matlab's x = eye(3); y = x(1:2, 1:2)?
 
 
2 hours later…
10:38 AM
@Luis this is a modified indexing case called fancy/advanced indexing. Basic slicing works with implicit tuples and cuts subarrays: x[:2,:2] is actually x[slice(2),slice(2)] is actually x[(slice(2),slice(2))]. If you change the tuple to a list or array becomes sub2ind-like fancy indexing: x[[slice(2),slice(2)]] or x[[0,1][0,1]]
And you can use np.ix_ to go from fancy index arrays to fancy slices that cut the corresponding subarray (this is rarely needed though)
 
 
1 hour later…
11:40 AM
It can actually be quite subtle: what I said doesn't explain why x[[0,1],[0,1]] invokes fancy indexing without an additional pair of brackets...
so the short answer is "slices with colons cut subarrays" ;)
 
another 3 German job adds today. Back goes SO to the addblocker list
 
12:45 PM
Add it to the adblock. And note the number of ds in "advertisement" :P
 
For some reason I always abbreviate "advertisement" as "add", not sure why
 
EBH
Well... finally I solved this!
 
1:06 PM
posted on June 23, 2017 by rruff

Richard is Consulting Engineer at MathWorks focused on the Embedded Coder product for code generation, primarily in the Aerospace industry. Richard’s pick this week is Source Control Information Block by Gavin Walker. ... read more >>

 
1:16 PM
Apr 20 at 17:56, by Andras Deak
you suck
 
EBH
1:29 PM
@AndrasDeak I turned it off from the profile settings
 
man, I'm really glad TMW decided to make the duration class not able to parse strings
and textscan not work on cell arrays of strings
to regex I go...
 
1:50 PM
>> cell2mat({'1', '2', '3'})

ans =

    '123'
:|
 
@AndrasDeak Ah, thanks for the explanation. So there are both.
Funnily, I recently introduced a similar thing in MATL: when indices are packed in a cell array they are treated sub2ind-like
 
@EBH it shouldn't be there in the first place :(
@LuisMendo should be real useful:) I know fancy indexing is.
 
EBH
@AndrasDeak You right.
 
Anyway it's a bug, I'll report it if no one has
 
2:43 PM
I'm thoroughly enjoying these guys right now
 
 
2 hours later…
4:26 PM
Please vote for dupe
-1
Q: Obscure numbers in machine learning(octave)

Kaloyan AleksievI have Octave related question. I have a dataset X which is in a text file and it has m = 47 rows and 2 columns. I want to normalize the values by substracting the mean and dividing by the standart deviation. I have written a function for this and the code contains a for cycle with which I change...

Use this as the dupe question
3
A: How to round double to something that a 'normal' human can read. (MATLAB)

rayryengUse format long g: >> A = 1.727287951101063e+04; >> format long g; >> A A = 17272.8795110106 You can check out the docs on how format works: http://www.mathworks.com/help/matlab/ref/format.html. However, format long g essentially represents your number with 15 digits, fitting all ...

 
I'm curious how you can get into something as math-heavy as machine learning and not know what scientific notation is
> Met vriendelijke groet
@Adriaan what is this gobbledygook :p
 
I guess Google translate can tell you it means "Best regards" or something, it's rather polite
 
I know, I was just taking the opportunity to make fun of Dutch :)
 
sure, have fun making fun of the Dutch, Im out for training :p
 
4:49 PM
@excaza I agree. That's why we should dupehammer :P
 
does anyone have an octave gold badge?
most of the top users are you guys, and the top guy is only silver
 
my guess for carandraug would've been correct, it seems
 
@rayryeng done
 
@excaza no one does because no one asks Octave questions here.
Only carandraug has the highest amount of votes and he's at a silver.
@beaker thank you sir.
I'm surprised that for someone who is working on machine learning, they don't know these things about precision.
 
5:04 PM
then again, nothing really surprises me on SO anymore :p
 
:D lol
 
@rayryeng no more surprising than people trying to do steganography and insisting that they can't access the LSB of a value unless they convert to binary ;)
 
@beaker face palm lol
Actually that was an interview question. They asked me two ways to find the LSB of a number without converting to binary.
I said find mod 2 and mask with 0x01.
 
 
1 hour later…
6:13 PM
does anyone know if containers.Map can be assumed to be order preserving?
 
@excaza i seem to remember it's not... let me find it
 
@excaza is that a java map
 
> The order of the values is determined by the order of the keys associated with them.
I don't take that back ;)
looks like it's just in the order imposed by the hash function
@ballBreaker There must be some difference because you also have access to java.util.HashMap
 
Yeah all Maps are typically hashmaps (unless otherwise stated)
that's why I was wondering
 
> since containers.Map is actually a scaled-down implementation of java.util.HashMap...
don't know if that's true or not
 
6:23 PM
I suppose I could have just entered commands to look :p
didn't notice that other doc page
>> tails = containers.Map({'accel', 'gyro', 'altimeter', 'GPS'}, ...
                          {'PDR.accelerometer_hg', 'PDR.GyroScope', 'PDR.altimeters', 'PDR.GPS'});
>> tails.values

ans =

  1×4 cell array

    'PDR.GPS'    'PDR.accelerometer_hg'    'PDR.altimeters'    'PDR.GyroScope'
very much not preserved :)
and case sensitive
I'm also going to continue my whining from yesterday about this stupid datalogger that outputs four stupid CSVs, all with different stupid timestamps
 
hehehe
It looks like someone is trying to implement it in Octave without the hash :/
 
> Now, with current implementation, keys will be automatically sorted appropriately (and relatively quickly) when using the constructor. Ordering using orderfields() will still be called when a new key/value pair is added to the map, and this will be slow for large maps:
:|
 
well, you either get sorted keys, or you get O(1) access...
hard to have both in limited memory
 
 
3 hours later…
9:08 PM
I never knew this existed. I played around with this a bit, and perhaps you'll like this gem: x=42;y=54; f=@(x)eval(inputname(1));f(x),f(y)Sanchises 5 mins ago
^ oh god
 
that Java answer doesn't look very short?
 
it isn't unfortunately
 
9:24 PM
I've always found it very disturbing that a function can access the name of an input argument
 
@LuisMendo why?
 
It's as if you were talking on the phone with someone and they could press a button and see you
 
Does it really matter though, that you know what the input argument is called?
 
haha, we are in the 21st century @LuisMendo it is possible now XD
@LuisMendo What would be really cool if you could change the name of the input variable :D
 
@Adriaan I dunno. But it's something personal, as I see it. I should be able to name my variables whatever I want without any function knowing that
@flawr But with your consent
@flawr Yeah, if you want introspection and mess, do it right :-)
 
9:27 PM
@LuisMendo still, why does it matter? The function can't do anything with it, it's a machine and it won't send the info to the NSA (at least not directly)
 
@LuisMendo not necessarily :)
@Adriaan not so sure, actually
what if the NSA knows all my variable names O_o
 
@Adriaan I feel my variable names are something private to me. No function should be able to know that
 
variable name encryption
 
9:41 PM
From now all I'll wrap my variables like this when being passed to functions
>> gossipy_function = @(x) inputname(1);
>> x = {[1 2] 'abc'};
>> gossipy_function(x)
ans =
x
>> gossipy_function(getfield(struct('tmp',x),'tmp'))
ans =
     ''
 
hehe=)
let's call it very-un-functional-programming
or disfunctional programming XD
 
@LuisMendo You could just put all your arguments in a cell array, then pass it as a comma-separated list:
>> c={1};
>> gossipy_function(c{:})

ans =

0×0 empty char array
 
why 0x0???
 
@flawr Because comma-separated lists are ninjas.
 
>> gossipy_function=@(x)inputname(1);
>> gossipy_function(i)
ans =
     ''
>> i=i;
>> gossipy_function(i)
ans =
i
 
9:58 PM
@flawr :-D
@gnovice Ah, much simpler!
But it requires defining the intermediate variable c
Or using your celebrated answer "ugly, but possible" to avoid it :-D
 
@LuisMendo gossipy_function(arrayfun(@(x)x,x)) works too
 
@LuisMendo 301 votes and counting!
 
jrh
10:17 PM
Quick question, do you need to manually delete a copied figure handle in Matlab or am I thinking of this too much like C++?
 
you don't need to delete anything
 
jrh
okay. So even for handles, when the object goes out of scope, Matlab automatically deletes it?
It must have some kind of GC internally I guess
 
jrh
oh, this is cool. Thanks!
 
@flawr Ah, that's neater than mine, and no intermediate variable
@jrh If you delete a figure with handle h (either by user action or with delete(h), the variable h still exists but "points" to a deleted figure. So you should probably delete the variable h, because it's not use anymore. Not sure if that answers your question
 
jrh
10:28 PM
So if h is a local variable in a function, and execution returns from the function, does matlab automatically call delete or should I?
I probably should have mentioned this was a local variable. I'm mostly just making sure there's no memory leak here (i.e,. h goes out of scope but doesn't get deleted)
 
@LuisMendo Surprisingly, they even tell you in the docs for inputname how to thwart it.
Maybe not that surprising.
 
@gnovice That's because they feel guilty for introducing such annoying, indiscreet function
@jrh If you do something like h = figure within a function, the figure won't get deleted. But h won't exist outside of the function (so you lose the handle to the figure), unless it's a return argument of the function
 
jrh
If the figure isn't shown though, is it a memory leak? I'm pretty much doing hCopy = copy(h); set(FigureHandleCopy, 'Visible', 'off'); -- if Matlab has a real GC then it's probably smart enough to figure out that the function is done with it and collect it at its leisure? (note: I didn't finish reading the article that flawr posted yet)
It's probably not like winforms where forms need to be deterministically freed, but that's my main worry.
 
Usually, graphical objects are not deleted with all their references are lost. I suspect that applies to invisible objects too, but not sure
 
jrh
Is there some kind of way to debug handles being allocated and freed? Like some kind of handle counter for Matlab like win32 has?
 
10:40 PM
I checked. The figure is not deleted. For example, you can still access it via gcf
 
jrh
oh, good idea
 
I'm not sure why you mean by handles being allocated and freed. That sounds like terminology from other languages which I'm not very familiar with
 
jrh
yeah, it's a C# / C++ / C thing
C# is technically garbage collected but the implementation of winforms causes there to be references held forever, meaning that if you don't manually Dispose (i.e., delete) them they will be permanently preserved using system resources.
 
In soviet MATLAB the functions call you
 
jrh
In C / win32 if you allocate a handle you have to deterministically free it because the compiler is incapable of signaling to the OS that the handle variable went out of scope.
 
10:43 PM
In Matlab, all variables are either local to functions (so they disappear on return) or accessible in the workspace via whos. Graphical objects are also accessible unless you have hidden them by setting their'HandleVisibility' to 'off'
And even for those, findall will find them
@flawr Chuck Norris doesn't call functions; he lets them be called by him
 
jrh
I guess that answers my question
the fact that this is all running on top of java is making my head spin
 
Hm. So when you close the figure, Matlab doesn't immediately free its memory, but only when required
Interesting
 
jrh
If anyone's curious I'm typing up an improved answer to this
40
Q: Get rid of the white space around matlab figure's pdf output

mjbrown2I'd like to use PDF versions of my matlab plots in a LaTeX document. I'm saving the figures using the "saveas" command with the PDF option but I get huge white space around my plots in the pdf files. Is this normal? How can I get rid of it? Automatically, of course, since I have "a lot" of plots.

all of the answers still have too much whitespace for me
I am copying the figure handle because the asm programmer in me hates to corrupt input arguments. If I were using this function I would not expect it to modify the input figure.
 
11:02 PM
matlab figure's pdf sucks
does copying the figure handle actually change anything?
 
jrh
Not that I know if. It keeps my code from messing with a figure that's already been shown.
And it seems like I have a good solution for fixing the pdf problem, what I've got now exports a nice vector pdf of just the plot and nothing else.
Sometimes this is what I want, sometimes I want axis labels so I'll probably end up with like 3 functions
 
that's nice
 

« first day (723 days earlier)      last day (2506 days later) »