« first day (2113 days earlier)      last day (1100 days later) » 

4:55 AM
@AndrasDeak What does that mean??? You assign first a = a[0], and then a[0] = [[]]? But a[0] doesn't exist at first?
No, there's something else going on here:
>>> a=[]
>>> a = a[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> a[0] = [[]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> a = a[0] = [[]]
>>>
This makes 0 sense to me. Both assignments are illegal, but the two assignments at the same time are OK?!?!?!
And what is the meaning of [[...]]?
 
 
4 hours later…
8:37 AM
@CrisLuengo I think a = b = c = x is just sugar for a = x; b = x; c = x
 
9:04 AM
so here a = [[]]; a[0] = [[]] (but don't take the second literally, this is two times the same array. so a just ends up being an array containing another array that contains a
so you have an infinite recursion.
 
 
2 hours later…
10:36 AM
@CrisLuengo almost what flawr said. a = b = c is sugar for tmp = c; a = tmp; b = tmp; del tmp
So you get t = [[]]; a = t; a[0] = t which is the same result as a = []; a.append(a). Python can handle containers that contain themselves.
So you evaluate the rightmost expression then assign that from left to right to each target
@flawr these are lists, not arrays
 
11:08 AM
@AndrasDeak maybe I'll remember some day
 
11:58 AM
hmm, this has passed under my radar until now
In [86]: np.s_[3:6, 15:20]
Out[86]: (slice(3, 6, None), slice(15, 20, None))
I'm pretty sure I could have used that, maybe in the recent past
 
12:13 PM
can you use this tuple directly as an index?
 
that's the point, yes :)
arr[a, b, c] is the same as arr[(a, b, c)] for any expression, at least as far as numpy is concerned (it might even be a more general python thing)
yeah, because __getitem__ probably gets a single argument
 
12:36 PM
ooh
 
1:13 PM
That's also why if you have an array idx of shape (3, n) that specifies n x, y, and z indices, respectively, you can index with that as arr[tuple(idx)]. Using arr[idx] or arr[idx.tolist()] would trigger fancy indexing, you only get basic indexing for a tuple.
 
1:41 PM
@AndrasDeak In this case, wouldn’t it be equivalent to a = [[]]; a[0] = a?
In any case this is very unintuitive behavior because it is not parsed left to right, nor right to left.
I find the C behavior more intuitive: a = b = c is parsed right to left. So your first get b = c, and then the result of that expression (which is the value of c) is assigned into a. In C++ you can overload assignment to evaluate to something else, which is rather dangerous... So you could end up with b equal to c, but the expression evaluating to 0, and so a = 0.
 
@CrisLuengo yes, but Andras' version it is obvious how it is generalizable to any number of things that recevie the assignment
"assignment victims"?
I think that was the reason he wrote it that way.
D: if we consider the permutation (n,1,2,3,....,n-1) as a linear map, then the matrices that diagonalize it are bascially the discrete fourier transforms!
 
1:59 PM
@CrisLuengo yes, but the result will be the same: a list that contains itself
@CrisLuengo yes, but also you never have to know this for sane use cases
just like these gems:
n [101]: d = {}
     ...: for k, d[k] in enumerate('potato'):
     ...:     pass
     ...:

In [102]: d
Out[102]: {0: 'p', 1: 'o', 2: 't', 3: 'a', 4: 't', 5: 'o'}
Just because I know how that works doesn't mean that any code should look like that.
 
@AndrasDeak beautiful!
 
Also, coming from C you might be surprised at the behaviour of a == b == c, but at least that's sane. (Unlike some other operator chaining examples...)
 
2:39 PM
such as
In [118]: 42 in [42] is True
Out[118]: False
(that's a pitfall)
 
3:04 PM
In [124]: 42 in [42] in [[42]]
Out[124]: True
 
staph the brainfuck
all that is cursed python
 
@AndrasDeak I don't think I want to understand how Python chains operators. I'll just stick to using lots and lots of parentheses.
 
Oh it's very simple. a op b op c is sugar for (a op b) and (b op c) etc. the pitfall is that in chains, when it shouldn't.
Sane chaning cases let you do 3 <= x < 42 and it does what you'd want it to do in math
a is b is c also defines an equivalence relation, although this is something that probably doesn't come up too often as a use case
when you start mixing operators or have in in there it gets messy and buggy
 
3:25 PM
@AndrasDeak I know this is true for comparison operators, but not for arithmetic operators. So is and in do this too? I think that’s a mistake...
 
@CrisLuengo I meant comparison operators. But also is and in, and I agree it's a mistake.
 
C++20 introduces a “spaceship operator”, which is kinda interesting. <=>. It is a comparison operator that returns a number, 0 for equality, the sign indicates which operates is larger.
For a class, default comparison operators are generated based on this result, so you only need to define one comparison operator for your class.
 
yeah, I read about that
 
The cool thing is that it also defines, by the return type, whether the class has a total order or a partial order, which generic algorithms can then use to do the right thing.
 
I suspect the compiler can do some tricks to make it almost no additional effort to implement the remaining comparison operators
in python the dispatch would be comparatively expensive
 
3:36 PM
Yeah, it is supposed to be a zero-overhead abstraction.
But then of course it’s not always:
25
Q: Is the three-way comparison operator always efficient?

Cris LuengoHerb Sutter, in his proposal for the "spaceship" operator (section 2.2.2, bottom of page 12), says: Basing everything on <=> and its return type: This model has major advantages, some unique to this proposal compared to previous proposals for C++ and the capabilities of other languages: [...] (6...

 
ah, you even have a question on that, nice
 
My bestest question, according to votes. :/
 
well and are apples and oranges :)
 
Yeah, is a hash place...
 
question "docs not clear" +35 updoots
 
3:46 PM
@AnderBiguri Dude, a self-answer. You're a hero!
53 upvotes on the answer
 
I literally read a book to answer that
 
LOL
 
those were other times tho, openCV 1.0
 
Awesome how it's 35 and 53 upvotes. I'm not going to upvote, don't want to mess with that beautiful symmetry.
Also, OpenCV docs are always unclear, except where they are wrong.
 
in this case, they were inexistent
 
3:50 PM
Sorry, I did break the symmetry.
No docs is better than wrong docs.
 
hahah thanks :)
I was in my masters back then and was so confused. Never done image processing, never done C++ or anything
 
4:18 PM
@Adriaan I hope your relatives are well dutchnews.nl/news/2021/04/…
 
@CrisLuengo Now we need |-o-|
3
 
@AnderBiguri back when baby Ander thought Community is a user stackoverflow.com/questions/16295551/… ;)
 
hum I am not really sure. Is it not possible that it was a mod and then it was passed to a comunnity?
ah nvm, dont remember
 
No, that's an approved edit suggestion by an anonymous user
But the UI is not intuitive
 
ah sure, buff, 7 years ago
I was not even thinking of a PhD then
 
5:17 PM
@LuisMendo YES!
 
5:45 PM
Ugh
 
 
2 hours later…
7:45 PM
@CrisLuengo SOME IDIOT
 

« first day (2113 days earlier)      last day (1100 days later) »