« first day (4440 days earlier)      last day (522 days later) » 

 
4 hours later…
11:48 AM
Cbg
I found the funniest bug in outlooks editor. It's a loop where it wants to correct soweit to so weit and then back again :D
 
12:43 PM
@Hakaishin hmm, isn't so weit in german? I don't trust google translate because it says "so far" as result, but based on context, it's probably not it
oh, you meant for correcting sentences. Nevermind, I think I got what you meant
using "endless spell checking" or "outlook grammar checking loop" seems to show that a lot of other people noticed similar stuff. No obvious solution AFAIK aside from a couple "reinstall" advice
 
1:47 PM
Is SE only slow for me today?
 
2:04 PM
test? anybody out there?
 
I am
I don't think I noticed any slowdown yet. Mostly just browsing on SO and SE right now
 
Hmm weird, google, twitter work. But stackoverflow is down for me so are the websites which check if things are down or not :D
ah whoops nvm I was in the wrong wifi
 
2:25 PM
Hi I have a quick question
 
Shoot
 
OK
I have this graph
I'm trying to fit the three points to a shifted version of the blue graph using scipy's curve_fit
My code is very simple:
x = np.array([425.5, 576.5, 685.5])
trialOne = np.array([148, 174, 160])*16e10 # Constant Scaling Factor

def fun(wavelength_m, p):
    return a/(((wavelength_m-p)**5) * (np.exp(h*c/((wavelength_m-p)*k*T))-1.0))

coef,_ = curve_fit(fun, x, trialOne)
print(coef)
But it gives me a coef of 1 which is nonsense
I would greatly appreciate any suggestions.
I've also tried providing a "guess" parameter p0, but then it just literally spits out my guess as coef
 
2:51 PM
What is the heapq library? I've tried looking at the docs but I don't understand
 
I'm not using any libraries beyond np and scipy and matplotlib
 
Sorry, this is a separate question from me.
I don't know scipy so I can't really help
 
heapq allows you to create a "heap" or "priority queue". It's a list-like data structure that can efficiently add elements, and pop the largest/smallest element.
 
@12944qwerty heapq provides the functions needed to maintain a heap list, namely to add/remove items. You can think of a heap list as a slightly weaker variant of a sorted list; the first items is the smallest (as in a sorted list) but then the sort criteria is subsequently for pairs, quadruples, ... and so on.
 
2:54 PM
So what's a heap list or "priority queue" then?
 
So the first item is the smallest, and the second and third item are second and third smallest – but the order between that pair isn't fixed for a heap. So you could have the order [1, 2, 3] but also [1, 3, 2] and both would be heap lists.
 
An ordinary list has O(1) adding, but finding/popping the largest or smallest element is O(N). Alternatively, if you keep the list sorted at all times, finding/popping the largest or smallest element is O(1), but inserting new values is O(N).
 
@MisterMiyagi so the first item is always the smallest, but the items after that doesn't have a guaranteed order?
 
@12944qwerty They only have a guarantee with respective to their respective "parent" but not amongst each other.
 
But it's an integer... there isn't a parent?
 
2:56 PM
It's effectively a flattened tree.
@12944qwerty The positions encode a tree-like parent child relation.
 
If I'm reading en.wikipedia.org/wiki/Priority_queue#Summary_of_running_times correctly, a heap has O(log(N)) adding, and O(1) popping. Much better than either of the naive list-based approaches
(... Usually)
 
What would the parent be then?
 
This SO post was quite helpful as a reference to me for understanding heaps.
@12944qwerty In my example above, the parent of both 2 and 3 is 1.
 
So the parent is the smallest item?
 
I do not fully understand how heaps work, but I understand* what they're good for. When it comes to specialized collection data types, I think this level of understanding is satisfactory
(*mostly)
Much for the same reason that I use Python's list.sort() without knowing how it works
 
3:02 PM
I'm trying to understand why it's used in dijkstra if it's not maintaining order
@MisterMiyagi What if you heappushed 3 after either of the lists? What about 2?
How does the item know what it's parent is when you push a new one?
 
@12944qwerty The item doesn't know. The heapq maintains that invariant.
 
How does heapq know then
 
Presumably Djikstra doesn't require "total" order, but rather just "enough" order to accomplish his goal. If so, the somewhat weak ordering guaranteed by heaps must be sufficient.
 
@12944qwerty dijkstra does only need to know the "next" smallest item. It doesn't care about knowing the exact ordering of all items.
 
would A*?
 
3:07 PM
Let's see. Wikipedia says, "Typical implementations of A* use a priority queue to perform the repeated selection of minimum (estimated) cost nodes to expand."
Priority queue, heap... Same thing in this context
 
A* also only needs to know the "next" smallest item. It just defines "smallest" more generally.
 
A silly metaphor: you are a doctor in an emergency room. Whenever you finish treating a patient, you go into the waiting room and get the most injured person. You don't need everyone to arrange themselves into a line from most to least injured -- you just need the most injured person in the seat next to your door, and everyone else can be a bit jumbled
 
For what it's worth, I've found the simple wikipedia version of articles really useful for getting an initial understanding of algorithms/data structures.
 
Ideally if someone comes in and they're more injured than most people, the existing people will mill about to get him a seat somewhat close to your door. But if he's not the most injured person, it's not a big deal if he's two seats away from your door or three.
 
3:38 PM
#Pycharm users, it would be nice to get some more votes for: youtrack.jetbrains.com/issue/IDEA-292704/…
Also today I learned about ssh-copy-id, my life has been changed...
 
3:51 PM
Heapq or queue library...?
 
As in, which one do I prefer? Right tool for the right job.
heapq for emergency room triage, queue for the DMV
 
What
 
To extend my silly metaphor, the DMV does not give priority to people with the most important business. It's first-in-first-out -- whoever shows up first gets served first.
 
@Kevin which always sounds like a bad idea
 
queue.queue is great at FIFO. O(1) put, O(1) get. Ideal for the DMV. Not so ideal for the ER.
 
3:56 PM
I have no idea what any of those acronyms mean
 
FIFO: first in, first out. DMV: department of motor vehicles. ER: emergency room. O(1): not an acronym
 
oh, thought they were programming terms
 
@12944qwerty queue is basically just a heavy wrapper around heapq (and others) to add thread safety. If the problem doesn't use threads, I don't use queue.
 
Hm, what does dequeue do?
 
it's like queue but without threading and in a different sorting/order (AFAIK)
 
3:58 PM
Not sure what language this code is in, but it does priority_queue queue(); ... queue.dequeue()
 
That seem C'ish.
 
@Kevin Yeah if you consider the DMV a separate entity of the customers. But obviously a business optimizing business + customer compared to just business side will succeed. This is a pet peeve of mine, that many places don't have appropriate sorting of issues, but it's getting better in the last few years, many places also do have some sort of smart queuing strategies(ikea, shops, some gov agencies, medical places)
 
collections.deque has O(1) pushing and popping from both ends. Compare to a regular FIFO queue, which can only push on one end and pop from the other end.
 
you can emulate queue using deque btw. Just use popleft instead of pop and it works
also use append but that one is obvious
the only problem then is adding threading support, but that one is relatively easy. don't know if it'll be the same speed, however
 
Deques are thread safe, apparently.
 
4:04 PM
hmm, used it here as mentioned last time, so I'm not really sure if it's thread-safe. It probably is but I didn't really check
 
Are deques different than the dequeue function?
 
@Kevin The GIL makes individual operations thread safe, at least. Though iteration isn't thread safe, for example.
@12944qwerty There is no dequeue in Python, as far as I can tell.
 
I'm assuming, based on context, it is the same as heappop
Nvm, the functino was defined earlier in the article lol
 
Ah, I misread "dequeue" as "deque". Yes, they're different things. I would expect "dequeue" to mean the same thing as "heappop" in the context of descriptions of priority queue behavior
 
Can I change the queue priority of the node?
 
4:17 PM
@MisterMiyagi I mean there this though? : docs.python.org/3/library/collections.html#collections.deque
unless you meant something else
 
@12944qwerty Generally, no
 
@Kevin that explains what MM said. Nvm then
 
context (i'm on dijkistra section)
 
IIRC neither Dijkstra nor A* need to change the priority of a node once it's in the priority queue
 
@12944qwerty Not sure what language that is, but definitely not Python.
 
4:27 PM
I realize that, I'm porting it to python. It's the only article I found that explains it the best
 
@Kevin Technically they do, but it's easier to just push in duplicate nodes and filter for those already processed.
Updating nodes looses the advantage of having a heap in the first place.
 
5:05 PM
Hi guys, does anyone have experience with scipy's curve_fit? I have a quick question.
 
5:15 PM
@MisterMiyagi I think it might be in C++, at least based on how the while loop is written, but not sure
@12944qwerty I did find this though: github.com/martiansideofthemoon/Algorithms-Practice/blob/master/… have a couple example implementation
 
5:59 PM
Just noticed that __str__ isn't really called when printing a list with those classes...
 
__repr__ is called instead of __str__ in some circumstances
 
that does explain why repr give similar output to print
I recall I played around with that when I was trying different encodings
 
bruh this pathfinding isn't working :(
 
@12944qwerty Yea only realized when I saw a canonical
 
nvm, turns out my get_neighbors was doing something weird
 
6:06 PM
The items inside a list calls the __repr__ method instead if __str__
 
6:18 PM
@DelriusEuphoria Yeah, that's because the list may have Objects stored.
__str__ is more specific usage.
 
The docs describe __str__ as the "informal" representation of an object, and __repr__ as the "official" representation.
 
Yes - so even if overriding I believe __repr__ should be mostly generated by internal refs while __str__ can be basically anything you want.
 
Yeah
 
Python programming (is to) Python backend encapsulation (as) HTML5 (is to) Javascript :D
 
In my experience, it doesn't matter too much if your repr is a bit informal, or your str is a bit uptight. It's mostly for the benefit of the person debugging your program, and if that person is you, then you can decide for yourself whether it's worth adhering to the doc's recommendations
 
6:33 PM
@Kevin Serialization doesn't leverage repr? I can imagine someone coming along and dumping objects vs proper introspection (innocent)
 
Serialization is usually done via pickle, which doesn't use __repr__
There are a variety of double-underscore methods you can define on your classes to make it play nicely with pickle: docs.python.org/3/library/pickle.html#pickling-class-instances. Although apparently you usually don't need any dunders at all
 
6:56 PM
Pure canon is that eval(repr(obj)) == copy.copy(obj). But as @Kevin states, your level of compliance is discretionary.
 
7:14 PM
If anyone is going to use eval in conjunction with my code, I would prefer not to reward them with easy serialization
I will instead harvest $1 worth of bitcoin using their hardware, then raise an Exception("Nah")
 
8:06 PM
def test():
    date = 01/01/2020
    ..
    pass

def main():
    date = 12/12/2022  # set by user
    ..
    pass

if __name__ == '__main__':
    # a, b, c = test()
    a, b, c = main()
Users modify main() in main.py on each execution while I uncomment test() for development purposes.

To move interaction from python file to a batch file (rather than command line), I am thinking about using argparse. Is it the right choice?

I guess it requires some restructuring of the code as values will be submitted from a .cmd file.
 
I'm not too sure I understand the situation, but if adding a command-line interface can solve your problem, that should be perfectly reasonable. You might want to use something more modern than argparse though. Like typer or fire
 
Thanks, will look in typer / fire. (Why is argparse built-in and these are not?)
 
Nothing modern and innovative is ever built in, that's just not how innovation works
 
in what situations do we need to use partial function from functools ?
 
8:32 PM
Use partial to define a function that you will use multiple times, with some of the parameters being the same every time. Say you had a function for the distance between two points dist(x1, y1, x2, y2). You could use partial to define dist_from_origin = partial(dist, 0, 0)
This would take the place of dist_from_origin = lambda x, y: dist(0, 0, x, y)
 
@PaulMcG hmm, so what advantage it provide over this lambda function, work wise both behave same
 
9:06 PM
Writing x and y twice is a pain in the butt. Seriousness level: 100%
 
XD, well that make sense
 
9:31 PM
There is also a chance that partial, being part of the standard lib, might implement this little function in some cool performant way (implement in C? generate some custom bytecode?), while lambdas are always going to be slow.
 
 
1 hour later…
10:55 PM
Although after looking at the code, that doesn't seem to be the case. partial builds an object that has a __call__ method that fills in any given or named args before calling the func object passed in to partial(), so probably largely a matter of taste. Note that many folks see lambdas as code ugliness.
 

« first day (4440 days earlier)      last day (522 days later) »