« first day (2075 days earlier)      last day (1148 days later) » 

12:44 PM
I thought I had \th defined as the hyperbolic tangent. But there's a latex built-in by that name: þ
 
 
5 hours later…
5:33 PM
Don't you guys find it inconvenient that in Python the function signature is split between the first line and the last line / lines?
Matlab: first line: function [y,z] = foo(a,b,c)
Python: first line: def foo(a,b,c). <lots of lines of code>. Last line (or some other line): return y,z
 
6:22 PM
@LuisMendo no, I always found that weird in MATLAB
and in python functions can return anything (although they arguably shouldn't)
Well-written functions have appropriate docstrings that tell you what it returns when
MATLAB's version reminds me of fortran subroutines where you have to asign to the function name what you want to return
@AndrasDeak *functions, not subroutines (I wanted to say that right but failed)
 
7:21 PM
@LuisMendo ad Andras said, usually it should be clear what you get anyway, but if you want you can do type annotations!
 
Maybe I've been spoiled by so many years of Matlab, but I find it easier to have the full function signature in the very first line
 
7:41 PM
@AndrasDeak To me, Fortran's way is more similar to Python's than to Matlab's, in that knowing what the function will return forces you to look through the code
 
@LuisMendo no, it doesn't
 
What doesn't do what?
 
a function called foo will return the value of the array foo
"what the function will return forces you to look through your code": no, it doesn't
 
Ah so Fortran only can return arrays?
 
fortran functions return a single thing, and pretty much everything is an array (sound familiar? :P)
 
7:44 PM
Ah, ok
 
fortran subroutines don't return anything, but rather mutate some of their inputs
hence my annoyance with using the wrong term despite concentrating not to
 
Anyway, I find it annoying in a Python function to have to find the "return" line in order to know if the function returns say an array or a tuple of three arrays. In Matlab that's clear from the beginning
(Except Matlab's functions' arity is variable, I know...)
@flawr I'll have to look into that, thanks!
 
@LuisMendo are you using an IDE?
 
8:04 PM
@flawr I will use mostly Spyder. For know I've used IPython online for this course
 
oh ok, I'm not a big fan of spypder, it is ok for some quick calculations and plots, but for everything else I like using a IDE that is a little bit more intelligent. I have some experience using pycharm and like it quite a lot. I recommend giving it a try!
there is even a VIM plugin in pycharm:P
 
8:23 PM
@LuisMendo you need documented code
 
there is no space for documentation when you're golfing:P
 
that's not just a style choice with python, it's crucial because code is too flexible
In MATLAB you can be reasonably sure that most inputs are arrays, and most of them double.
 
8:37 PM
@AndrasDeak My “complaint” is more about the number of outputs. Anyway, I guess when you are used to a language many things look unfamiliar
I do like Python’s enumeration, to loop over an array and get the index simultaneously. That’s something I miss in Matlab
@flawr Is that a pro or a con? :-P
 
@LuisMendo haha good question, I guess it depends who you ask:)
 
8:49 PM
@LuisMendo but my point is that a function might have multiple returns
you can't (easily) enumerate it in one place
 
9:39 PM
@AndrasDeak when I have a 2d array (gray image) img I can easily fill the inside of an (axis aligned) rectangle using img[a:b, c:d] = value, but how would you fill the outside?
I did mask = img*0; mask[a:b, c:d] = 1; img[~mask] = value but is there a better way?
 
I'd use a bool array but I can't think of a better option
unless starting with a full image of value and replacing the inside
seems similar to me in terms of ugliness
 
is there maybe a quick way to get like a meshgrid-thing of the size of the image
 
np.indices(img.shape)
sorry, not too golfy :P
 
10:00 PM
oooh very nice, thansK!
it even has a sparse option!
 
yeah, that's basically an mgrid/ogrid shorthand
 
too bad you can't do the chained comparison here: img[3<x<5]
 
you can do img[(3 < x) & (x < 5)], but yeah
 
just found there is also np.full_like, which seems to be the cleanest way to create a mask for an array
 
10:18 PM
No: np.zeros_like/np.ones_like with dtype=bool.
full is for other values
 

« first day (2075 days earlier)      last day (1148 days later) »