« first day (4526 days earlier)      last day (645 days later) » 

00:17
stackoverflow.com/questions/65076752 this is a duplicate (and a very bad one). The canonical is stackoverflow.com/questions/11205254. I'm not sure why I closed and reopened it; it might be because I thought the canonical I had at the time was not very good.
or it could be because there are other problems in the code, idk
In a neural network with 2 hidden layers each with 100 neurons and 20 samples passed into it. Should the hidden layer errors be 20 x 100 in dimension?
PEP-709 Draft, currently for 3.12 - performance enhancement to list/set/dict comprehensions used inside a function. Currently, comps generate bytecode to create a small function containing the logic of creating, building, and returning the list/set/dict, call that function, and save the result. This PEP does all that work inline, with guards against accidental overwriting of local vars with the same name as vars in the comp.
So no function creation, no function call, no frame create/destroy. If you avoid using vars whose names clash with locals, then you can also avoid the push/pop of the locals before and after the comprehension runs.
01:33
@KarlKnechtel Nah, I also already thought it's too long, trying too much maybe. And while I do like such trickery, I don't think it belongs into such Q&As intended for beginners, would only confuse them. That's why I only mentioned it here, just for fun.
01:54
fair enough
I did reorganize so that the main answer focuses on the three techniques, and then there's a second answer that covers things that can go wrong and special circumstances (the case study, pun intended, and the stuff about modifying an input list)
I might eventually decide that the while loop stuff doesn't fit in this Q&A anyway.
But first I want to work on other canonicals, such as a more practical reference for list comprehensions
(i.e., something that shows flattening and filtering, and references a bunch of other questions)
and something for "scan a list and see which elements meet a condition" (reference for filter, all and any type questions, and the related list comprehension syntax)
(except that one would point out a ton of special cases where there's something smarter to do, and link those canonicals)
duplicate; see the comments and question history stackoverflow.com/questions/75091926
phew. it was a long day.
02:36
__add__ is to __radd__ as __getitem__ is to ...? Is it possible to define the result of the [] operation via a method on the item rather than the container?
02:51
Don't think that makes much sense at all, as the it implies some sort of reference from the item being returned pointing to the container that the container somehow has access to (in which case, just skip ahead and use the reference from the container to the item directly). Also it does not exist.
 
5 hours later…
Anonymous
07:56
How do you guys name "pathlib.Path" variables?
Anonymous
If you have a "destination" path, are you naming it "destination_path" or just "destination"?
Anonymous
Do you name a path to a screenshot "screenshot" or "screenshot_path"?
08:09
That completely depends. In the past people suggest that this verges on hungarian notiation and isn't necessary. However, with screenshot, that might well be a 2D array of pixel data, so I don't think the "path" qualifier hurts
If it's all enclosed in like 10 lines of code then I don't think anyone is going to struggle to understand it either way, though
@user76284 Not unless the container explicitly calls something on the item. E.g. for a dict the item has some control over the lookup by defining __hash__, but that's about it.
08:26
@Warcaith There are some common names that are clearly paths (or pathlike) to me, for example source/destination. But for screenshots I agree with roganjosh that just screenshot is too ambiguous and a postfix helps.
The official Mac site is funny. I decided to see whether I could trade in my Windows laptop for a discount; first question "what brand is your laptop?" with only "Apple" and "Other" as options. As soon as you click "Other" --> "Based on what you've told us, your laptop is ready to recycle". Ok, then.
They've stopped doing 16GB RAM on their 13 inch models :'(
08:48
@roganjosh Well, they're just stating the facts. :P
It did give me a chuckle :P
@roganjosh I still see the option to upgrade from 8 to 16 in the shop for the MBP. Are you looking for a particular model?
Oo, you're right, I thought they were just selling the base models listed since the second one jumps on SSD size, and yet that's also an option for the 256 model too. Need to pay more attention
I hope they keep 13″ @ 16GB for a bit longer. Need to convince my boss that it's time for a new one...
Hopefully the media editing aspect will keep the RAM up, while everything else seems to be migrating to web books because clouds n stuff are cool
09:08
Well, I can't believe I just did that. No holiday this year!
09:25
In the cloud, every day is holiday!
£200 for an extra 8GB of ram. It's like being back in the year 2000!
Oh well, I'll be super productive 24/7 now. At least I'm going to keep telling myself that
I've been pretty impressed by the lower power consumption of the M-series macbooks.
MissMiyagi has one and it's absolutely not comparable to my old electronic heating device.
Yeah, I've been listening to a few channels I like on YouTube discussing how Intel has basically been blown out by it. When the M1 was released, I spent a lot of energy to make sure I stayed on Intel because of compatibility problems that my colleagues had but they seem to have dwindled now. I'll be really upset if OSRM won't compile on this laptop, though, because it's basically a dead project but a pretty crucial feature in my playground
So you'll get back those £200 eventually...
@roganjosh I'll be honest, compatibility is still a pain every few weeks here. Most things work but it's apparent the build chains don't specifically target/check the M-Series.
If the source is available, that usually makes things easier as far as I can tell.
Does Docker do anything to mitigate it or is the chipset too fundamental a component?
I don't know nearly enough about VMs to know whether they can do anything at all to help in this case
09:38
AFAIK rosetta lets you run "Intel Docker" if you really want to.
Usually compatibility problems are due to compiled-for-speed libraries targeting wrong ABIs (don't pin your numpy versions, kiddos!) so mitigating this with Docker+Rosetta would often defeat the purpose of using them in the first place.
Better that it runs albeit slowly than not run at all :D To be honest, I think only OSRM would be the one I'd be running in Docker anyway since it's a standalone service. And I'll just never use HDBSCAN because getting that thing to compile on any machine makes kittens cry
Poor kittens... ;_;
 
1 hour later…
10:55
How do I use distinct with select(User).... in SQLAlchemy? I only find it used as Session.query(.....).distinct()
That's the correct way to do it. I'm not sure I follow the alternative you're looking for?
Aren't there 2 options when querying? (I'm currently learning sqlalchemy). I am using the one with select():
...
query = select(User).join(Company)
query_result = await db.execute(query)

return query_result.scalars().unique().all()
Isn't this the right way to do it?
11:11
So you're looking to remove Session.query, similar to this?
As for select(User), I'm not familiar with that syntax sorry but I haven't really used an ORM for ages
From what I just found, it's the new style for sqlalchemy 2.0. I guess that's why I was encouraged to use it. I'm trying to use distinct with the new syntax.
That page includes this example snippet:
# 1.4 / 2.0 code

stmt = (
    select(User, Address.email_address)
    .join(User.addresses)
    .distinct()
    .order_by(Address.email_address)
)

result = session.execute(stmt).columns(User).all()
11:29
Interesting... TIL I know far less about SQLA these days than I thought. That's quite a large shift in syntax
It feels very similar to my littletable API (which I originally wrote to get a better understanding of SQLA and its ilk).
@PaulMcG That's what I need. I ll try to make it work for my case now.
12:12
Cbg people
shouldn't this be True not False?
isinstance(5, float)
@Hakaishin this only refers to type hinting, not actual types
I see, doesn't this being False violate Liskovs?
I seem to recall Aran having a mini meldown about the typing of Numbers not too long ago but, yeah, it was just about typing
print(issubclass(int, float)) # False
It doesn't because int is not float's subclass
isn't that like mathematically wrong?
12:16
@Hakaishin Practically, floats are used as Real values which are a subclass of Integer values.
But technically they aren't.
I'd say no, as mathematically numbers don't have types
IIRC isinstance(5, numbers.Real) should work.
float is an implementation of numbers.Real. See docs.python.org/3/library/…
>>> import numbers
>>> isinstance(5, numbers.Real)
True
hmm and floats are not subtype of real?
12:36
Int is real. Float is real. Int is not float.
I never thought twice about it, but ints being a subtype of float is actually kind of weird
@Aran-Fey why would it be weird?
Well, usually a subclass has more bells and whistles than the base class, which means it can represent things in a more detailed fashion. A float is like a subclass of int with the added feature of decimal digits
(But of course float being a subtype of int would violate the Liskov Principle in a billion different ways)
12:54
In my mind I had this picture in mind, here it would look like int's are a subset of floats
but I guess it's a faulty model of how ints relate to floats
@Aran-Fey Actually, on 2nd thought, this might not be true after all
I don't have enough brain power for this topic right now :/
@Aran-Fey and the added bug of inexactness
x + 1 doing something different would surely violate Liskov
But... that does something different
@Hakaishin we have to disentangle "float" from "real number"
@AndrasDeak--СлаваУкраїні what do you mean? Floats have limited precision, but within this precision their are exact
@AndrasDeak--СлаваУкраїні true, I guess floats are not real numbers, even though I think of them as such
The limited precision makes this extra spicy, because floats can represent things that ints can't, but also ints can represent things that floats can't
I feel like I've been transported into the body of one of those people who post things like "I don't understand inheritance, why is House a subclass of Building?"
Don't you think this is similiar to the "is Square subclass of Rectangle" problem?
In some ways, sure
Sure, all squares are rectangles, but when implementing Square it doesn't really make sense to stick with Rectangle's interface
I think that's less confusing because you can't think of a rectangle as "a square with something extra"
...is it valid to think of a float as "an int with something extra"? Maybe that's not how mathematics work
"real" or "rational"? :P
Because "reals" aren't int extensions. The (u)int definition is "there's a next number".
reals have no "next one"
Yeah, we have to differentiate between mathematical sets (integers, rational numbers) and their programming implementations (int, float)
I guess this picture made me think that ints are a subclass of floats, but floats are not reals so it does not work. Now I wonder where floats go in this picture
Hmm. Is that the part we care about, though? Pretty sure we just use ints to do math, not to find "the next one"
13:25
Although, since ints are used as list indices, I guess we do care about finding "the next one"
Anyway, I gotta run
I guess the real question is what are floats mathematically speaking, no pun intended :D
@Hakaishin floats are implementation of Q
I see
@matszwecja wouldn't that imply that ints are a subtype of floats?
No, because they are related on a mathematical level, not programming one. Just like I mentioned with squares and rectangles. Squares are rectangles, but it doesn't make sense to implement them as such.
It's the switch from abstract maths to actual implementation that forces us to drop the relation between int and float
13:37
I kinda follow, but it would be nice to understand the topic in more detail :P
 
5 hours later…
18:42
I am having trouble understanding zip, so list(zip([1, 2, 3], [1, 2])) == [(1, 1), (2, 2)] every element is zipped with the corresponding element if present (shorter list) but list(zip([1, 2, 3])) == [(1,), (2,), (3,)] should it not be [] as there is no corresponding element? how do I understand this
@roganjosh this is not new syntax, iirc it is the "core" style which has always been present, they just unified core and orm syntax
@Jake zip works with an arbitrary number of arguments (iterables) so there's no reason to special case 1 or 2
"For any iterables that are passed as arguments, take one item from each and yield them in a tuple, stop if any of the iterables runs out". Now do this for a single iterable and see why you get what you get.
in fact zip can handle so many arguments that the way to unzip an iterable of tuples is to call zip with the iterable unpacked inside
as in zip(*...)
thanks, your English explanation makes sense to me
you mean list(zip(*zip(foo_list))) == foo_list?
actually ignore what I said, but I got what you said though
19:21
@Jake I don't think that's true. I use core every day and I do it specifically to manage connections, nothing more. All of this syntax is for the ORM
19:43
@roganjosh from docs.sqlalchemy.org/en/14/tutorial/… "For both Core and ORM, the select() function generates a Select construct which is used for all SELECT queries"
and that is 1.4 docs not 2.0
21:20
@Jake I almost wrote something like that but I realised that it would be hard to come up with a specific example that's both correct and instructive without testing it first :P

« first day (4526 days earlier)      last day (645 days later) »