« first day (3888 days earlier)      last day (1054 days later) » 
00:00 - 20:0020:00 - 00:00

12:13 AM
The docs claim that the final code block at numpy.org/doc/stable/reference/generated/… takes extremely long to run, but maybe in numpySpeak that means "more than one second but less than two"
Does it mean anything if my eigenvector has only negative values? I generated some more realistic test data and all the page ranks are below zero.
The results aren't total nonsense, because the lowest-ranked node, G, is the node that I specially crafted to have the highest page rank. So maybe I can just multiply the vector by -1 to get the output I want.
I may have generated my directed graph with all the arrows backwards... I better double check
 
@Kevin no, you can multiply any eigenvector with any complex number and it stays an eigenvector with the same eigenvalue. I like to call them "eigendirections".
@Kevin you can
 
Ok, cool. I was going real deep down the rabbit hole trying to think of corner cases where the magnitude was important
 
Common question of "oh no my eigenvectors are different betweeen language A and B". There are two reasons why this can be normal; this is one of them.
 
12:29 AM
One idea I was toying with earlier was the concept of "taxicab-normalized vectors". A vector is taxicab-normalized if the sum of its scalar values equals 1. I wanted to find a linear transformation matrix that would guarantee that M*V is taxicab-normalized if (iff?) V is taxicab-normalized. But I'm 99% certain this is impossible.
 
Hmm, maybe. You can look up p-norms with p=1 if that helps.
There's always the unit matrix and its multiples, e.g. the zero matrix
 
I think this mostly because a vector can be taxicab-normalized in one basis, but not another. Suppose V is (1,0) in the regular old x-and-y-axis basis. Then it's (1/sqrt(2), 1/sqrt(2)) in the rotated-by-45-degrees-basis. One of these is taxicab-normalized and the other isn't.
 
That's true for any norm.
You're looking at norms in the same basis before and after transformation.
I think you're looking for the C4v group
 
Oh, very interesting
I don't understand half of this but I'm pleased merely to discover this isn't a dead end
 
I.e. the group of transformations that leaves a square invariant
90-degree rotations, reflections over principal axes and diagonals
These all transform Manhattan into itself
 
12:38 AM
Ah, that example sheds quite a bit of light on things
 
Got to sleep now, but let me know if you have linalgy issues later
 
Thanks for your sage guidance :-)
 
 
4 hours later…
4:53 AM
How can I pass parameters to a TKVariable trace? dupe, the link is given in the comments
 
5:08 AM
@Aran-Fey we'll have a proper teaching website for you :D
 
 
1 hour later…
6:27 AM
Is this true?
0
A: How should I use the Optional type hint?

Alon BaradUp until Python 3.9 if you wanted to hint for a nullable value you had two options: import typing def foo(bar: typing.Optional[str]): .... def foo(bar: typing.Union[str, None]): .... From Python 3.9 you are not required to use typing module: def foo(bar: str = None): ....

also the dude has 420 rep
 
I believe so I tend to use
def find_search_input(driver: object, code: str):
 
6:46 AM
I mean adding the none type implicitly in 3.9
should still be optional[str]
 
7:43 AM
Morning cabbage all
 
7:54 AM
cbg tinfoil
 
How are we all doing today?
 
feeling quite good myself, how are you?
 
Decided to do an unsolicited refactor to fix linting errors (some of which were blocking), and the MR will likely piss off my coworkers and communicate that I have nothing better to do. In retrospect fixing stuff was not strategic.
 
Sanity is a bit frayed - but who's isn't these days?
 
can't wait to see something that isn't within 50km of my home, hopefully sometime soon.
 
8:00 AM
You can look at the stars, they are perhaps further away
 
:p
 
Why would it not be strategic Mikhail? Is someone else meant to be fixing the issue?
 
"how far is that star away?" "at least 50km. I think."
 
You know, that might be one regret I'll always have - not taking the time to properly get into astronomy during lockdown
 
lockdown's not over yet, right?
I also tried to pick up now hobbies, baking bread and making pralines. it's also been a while since I did either of those.. motivation was a lot higher when lockdown only looked like something that'd last a couple of months
 
8:08 AM
It's over in switzerland, but it wasn't very serious to begin with
 
@OldTinfoil Somehow its hard to communicate the value of code maintenance. Perhaps this is modulated by the size of your team.
 
@Mikhail there is lots of sources that can help you argue for it
 
@AndrasDeak Not using numpy myself, but helping out with a group that does. This is gonna come in handy, TY.
 
@Mikhail I found a nice analogy while doing some refactoring. Imagine a Pizza store and it delivers pizzas just fine. But now you also want to sell paste, for this you need different equipment and different machines, so you need to reorganize the shop to be able to produce pasta. You need to make space for the new stuff and look that new and old stuff doesn't interfere. Ofc if all you want is pizza code maintenance is useless, but assuming you don't want to build a whole new store but reuse
parts of it to make paste, utilities, the space etc. You will have to do some rearranging/refactoring
 
@Arne True that.
@Hakaishin You've never made pizza professionally have you? haha
 
8:13 AM
@OldTinfoil ofc not :D
 
Thought not ;)
 
@Mikhail for things that are hard to argue in favor for because they do not have immediately obvious value, I always like the "no broken windows" metaphora from pragmatic programmer, on of the few books on programming that I'd broadly recommend.
and also this maybe: chelseatroy.com/2021/01/14/quantifying-technical-debt not cleaning house regularly means you pay for it in the future. kind of obvious of course, but this article tries to attach concrete numbers to that wisdom
"no broken windows" -> once you start slipping with how well you care for your code, i.e. once your neighborhood has broken windows, the overall quality is going to decline steadily, because things are already bad and keeping the grass nice and cut looks silly if your house has wooden boards nailed over of holes.
 
So another amusing thing is that a lot of my coworkers are python programers, but our code base is so large we're getting messed up by type related failures. But fixing the type annotation is hard to explain.
 
8:41 AM
Hi, anybody here?
I'm at my wits' end, and maybe somebody can help me to orient myself sufficiently to at least have a real question for the front page
 
What is it
 
I am writing a unit test which should assert that a log message was written. It always calls the real logger of the module instead of the patched one, so the unit test fails. I have been sitting at this for hours, even re-built my complete project structure as an MWE. The same code works in the MWE, but not in my original code. I have no idea where to continue looking for the cause.
 
you use unittest or pytest?
 
unittest.
The test code itself is straightforward, I think
> @patch("echopdfdatahandler.logging")
def test_wrong_order(self, mock_logging):
input_string = "mit guter noch Pumpfunktion"
result = EchoPdfDataHandler.recode_pumpfunktion(input_string)
self.assertTrue(re.match("", result))
self.assertTrue(mock_logging.debug.called)
 
unittest means I'm out, though.
 
8:50 AM
And how are you using the logger?
 
I checked some obvious stuff such as that the name of the module is correctly written.
        logging.debug("unknown pattern: " + match_sequence_str)
 
Hmm, then the only thing I can think of is that you may have done something weird like def func(logging=logging):
 
As I said, the same way of calling the logger and testing works in a test project.
 
oh, maybe a simple one. did the module load before the patch could switch the logger?
 
@Aran-Fey I'll look where I am using "logging" but I am pretty sure I am not passing the logging anywhere as a function name.
@Arne I am importing the package at the top of the unittest file
 
8:56 AM
and you patch the logger that is used in exactly that module, right? because if you patch the import, it'd be too late for that
juggling import patch timings has always been a great source of joy in my tests
 
@Arne I think so. I must admit I am new to Python, so I may have done it wrong.
 
Is your project still structured like this? I'm starting to suspect that you may be importing the echopdfdatahandler module twice under two different names
 
@rumtscho if you're new and still have the option to switch, I'd like to advertise pytest over unittest. things like this would be a lot easier there
 
A proper project structure is like this:
project-name/
    package_name/
        __init__.py
        other_files.py
    tests/
    README
    pyproject.toml
 
@Aran-Fey pretty much yes, I renamed the file EchoPdfDataHandler.py into lowercase echopdfdatahandler.py, to avoid confusion when I am referencing the module and when I am referencing the class in it
 
9:00 AM
And your imports start with package_name, always. For example, import package_name.other_files. Never import other_files
 
@Aran-Fey I'll look into the imports now.
 
What I suspect is happening is that you're patching echopdfdatahandler.logging, but the function you're calling is actually from the dwhextractor.echopdfdatahandler module (and not the echopdfdatahandler module)
 
@Aran-Fey Now I am confused, don't both refer to the same thing?
 
They both execute the same file. But because they have a different name, python considers them two different modules
 
Also, did I understand you correctly, that I should import dwhextractor.echopdfdatahandler, and then always use calls like dwhextractor.echopdfdatahandler.EchoPdfDataHandler.recode_pumpfunktion? Or is it OK to import the class EchoPdfDataHandler too?
 
9:06 AM
You end up with two modules that are completely identical except for the name. And of course patching something in one module won't affect the other module
@rumtscho The point is that you must always refer to the module with its correct name, which is dwhextractor.echopdfdatahandler (and not echopdfdatahandler). Doing from dwhextractor.echopdfdatahandler import EchoPdfDataHandler is fine. Doing from echopdfdatahandler import EchoPdfDataHandler is not
Don't forget to add the dwhextractor. in your @patch call as well
 
@Aran-Fey that was it! Thank you!!!! I really would never have found it out on my own.
I didn't realize that the "same" module can be counted twice. I'll go now through all imports and redo them.
 
Yeah, the import system is... unintuitive, but easy once you figure it out
 
Do you know of good ways to debug it? Something to orient myself, to know which import I am calling, when I find a bug again?
@Arne This is an interesting suggestion. On the one hand, the project is not so large. On the other, I was glad that I have already finished it, this test was the last thing I was missing.
 
Hmm. Well, every class and function has a __module__ attribute, which can help you figure out where it came from. So you can do print(EchoPdfDataHandler.__module__) and notice that it doesn't print "echopdfdatahandler" (which is the module you were incorrectly patching)
 
@rumtscho only if you have time, then. it's an interesting framework to wrap your head around
and one of the few cases where, despite the standardlib having an integrated solution for something, a 3rd party package is more popular
 
9:22 AM
@Arne I currently have around 130 tests, with the complexity of the one I posted, or simpler. What would be a rough time estimate for the migration for somebody who already knows the framework?
and can you point me to some good resources for learning it?
 
strictly speaking 0, because pytest supports unittest
in general, it depends which unittest features you are using, and how they'd translate into "proper pytest style"
hard to say, I guess I could translate a hundred tests in day, if they aren't too complicated. if I didn't know the framework, I'd give myself at least a week.
 
I don't mind using "nonstandard" libraries. This is actually the first time I have ever had to code in Python. I have done much more work in R, and there it is absolutely normal that one uses third party libraries for the most common stuff one does. For example, R natively has data frames (and data structures of this format are really widely used) but there are two non-base alternatives which are so much better, everybody uses them instead.
 
if you give me ~5 of your tests, I could port them for fun, then you'd have something of a guideline how much work it is, and if you like the look of the pytest-style
 
In other news, I need some help figuring out how to use the Windows API to resize a window to a specific size. My problem is that the window allocates space for the title bar and a drop shadow, but I'm only interested in the size of the area where the contents of the window are rendered. I've managed to deduce the actual size I'm interested in, but I'm still unable to correctly set a window's size.
Here's my code so far. After setting the geometry, the x position is off by 8 and the y position is off by 31 (on my PC, at least). Would appreciate if someone could look it over
Well, I guess that means my problem isn't resizing, it's moving.
And naturally, I've figured it out 10 minutes after asking for help. Got it done with
client_top_left = wintypes.POINT(client_rect.left, client_rect.top)
user32.ClientToScreen(self._handle, ctypes.pointer(client_top_left))

x -= client_top_left.x - window_rect.left
y -= client_top_left.y - window_rect.top
 
9:39 AM
happy to help 🦆🦆
 
@Arne Thank you for your offer, I really appreciate it. On a second thought, I shouldn't be spending the time on such a change now - from the point of view of my boss, even redoing our loose bunch of redundant scripts into a single application was a bit of an overkill. But I will certainly keep in mind that pytest is preferable, and see if I can get into it in another project.
 
no problem, best of luck and lots of fun with python =)
 
10:00 AM
is the main site down for anyone else? I get a 503 page
 
@python_user It is OK for me. Do you know of isup.me? Quite a handy page.
 
funny thing is, I cant get that to open either, will have to try a different page, I checked isitdownrightnow, will check what you mentioned
 
I also get a 503 on the main site, but isitup gets a 200 ¯\_(ツ)_/¯
 
I checked in that now, "It's not just you! stackoverflow.com is down. Check another site?"
funny how chat survived :D
 
Same, down
"Error 503 Service Unavailable"
Afterall we are the heart of SO, if we were to go down, then SO wouldn't revive back anymore :P
 
10:14 AM
someone is getting all rep that could have been mine, 1.4k more till I retire temporarily
 
Retire temporarily, reminds me of Messi :P
 
I aim for 10k for the actual retirement, though thats a long goal
 
Not necessarily(you have more than enough knowledge to get 1k in a week or less), but it did take me a year
 
Lots of things are down, including Fastly
 
Hmmm, now it shows "connection failure"
 
10:18 AM
yeah same here, though this is the first time I am hearing of fastly
 
They're a CDN and it looks like it's potentially an issue on their side that has made lots of websites unreachable
 
@CoolCloud it should also remind you of GvR, he did eventually join Microsoft
 
Oh did not know that
 
10:33 AM
cbg. Why can't I open stackoverflow.com? Is it occurring for others? It sometimes result in 503 and sometimes in "connection error".
 
Yea, you can read above
 
I also get error in docs.python.org. Is W3C down for some reason?
Finally at least docs.python.org is now working
I don't know what's happening. Sometimes error, sometimes everything is alright.
Maybe docs.python.org was also having server maintenance. But stackoverflow.com is still down
 
Since all these sites are down, I think something that connects them with us is at fault
 
Probably, google servers?
Now github.com is also showing html code instead of a good inteface.
Something is wrong
 
whats going on with everything?
 
10:42 AM
Github works for me
 
Now github is up and python is down.
It's not consistent
 
Hmmm I don't think there is any point in discussing about it here, unless something new happens
 
Do you guys share an ISP or something?
 
I don't think so :p
 
Why did I open my mouth - python just went down
 
10:43 AM
Theyr watching you :P
 
Looks like some caching servers are malfunctioning
 
The servers going up and down
The error message says "Varnish cache server"
 
Half the images on this page won't load for me, so throw that in the evidence pile
 
@Kevin Exactly. Same is happening for me on github
 
Whenever more than one big website is down at the same time, my first instinct is to accuse Cloudflare
Even if there has never been any indication that any of the sites actually use Cloudflare. Doesn't matter, still Cloudflare's fault
 
10:47 AM
29 mins ago, by roganjosh
Lots of things are down, including Fastly
It's Fastly that has the issue as I said earlier
 
Ah, is Fastly a Cloudflare-like service? Very well, I will accuse them instead
Hey guys remember when the world wide web was supposed to be a decentralized network that's extremely resistant to single points of failure? Good times
 
Unfortunately Kevin, people started to weaponise toasters and lightbulbs
 
Now when a brownout occurs in a particular square mile of silicon valley, it means I don't get to look at funny cat pictures that day
If anything, weaponized toasters should have been impetus for more failure-resistance, not less
 
So many sites can't be on maintenance at once. Can it be that DNS resolution servers are down?
 
Government should be like "arpanet, but it can fire scalding toast at invading armies? Have a hundred billion dollars"
 
10:51 AM
I do like the opening statement of their status page here
 
@ShreyanAvigyan Haven't we already determined that it's Fastly that's down? Presumably it has a hand in serving all these other sites.
 
cbg. im surprised i can still access this. looks like the internet went kaput today
almost poetic the chat is up while main SO doesn't seem to be reachable :P
 
" Identified - The issue has been identified and a fix is being implemented. Jun 8, 10:44 UTC " -- pretty convincing evidence that it's their fault, because companies hate admitting culpability as long as they can pass the buck
 
@roganjosh That is nice and honest
@ParitoshSingh We are the untouchables
 
Well, given that they've knocked out half of the internet, I'm not quite so confident in their fail-over
 
10:55 AM
So DNS resolution server is down
 
Although I suppose the passive language there is a kind of weasely half-admission, since the issue, caused by somebody, has been identified, by somebody, and a fix is being implemented, by somebody.
 
So how is the day so far
 
I guess "Bob in marketing caused the issue, Alice in IT identified it, and Carl the intern is implementing a fix" is too personal
 
But whoever did find the issue and fixed it deserves some appreciation
 
Here's to you, maintainers of the spindly rectangles near the bottom of this chart
 
10:59 AM
Server's back up again. Thanks Fastly for fixing it so fast
 
Ah, I wasn't referring to the status itself but the actual opening line: "Fastly’s network has built-in redundancies and automatic failover routing to ensure optimal performance and uptime."
 
Ah, yeah, after reading your message a second time that's what I figured
 
Am back!! Everything is down there!!!
 
There's a reddit post that's like "The entire infrastructure of the Internet is completely dependent on the maintenance performed by about 50 tech professionals around the globe. I know many of them, and incidentally a lot of them are furries"
Alice and Carl in the above hypothetical are members of this shadowy cabal. They are our protectors in the dark.
 
Thank you Carl and Alice
 
11:21 AM
I suspect they're well-compensated, but the fringe benefits alone might make the job worthwhile. They have physical access to the Backbone, the largest internet tube that all the other series of tubes feed into. Plugging your personal laptop directly into it is like the stargate from 2001 A Space Odyssey
 
That pic above resembles the state of my mind when I am solving Sudoku, impossible thing for me.
 
hello
arr = [
        {
            "name": "name1"
        },
        {
            "name": "name2"
        },
        {
            "name": "name3"
        },
        {
            "name": "name4"
        }
    ]
    print(arr)
how to make it new dictionary and remove the dictionary item from name2?
I want to get ,
arr = [
        {
            "name": "name1"
        },
        {
            "name": "name2"
        }

    ]
in a new dictionary, how can I do it?
 
You mean a new list? Containing only the first two elements of the other list?
 
Do you want to specifically remove all items after the one named name2, or do you just want to keep only the first two (whatever they are named)?
 
11:38 AM
Do you want a new list or do you want to mutate the existing list?
 
11:50 AM
@Kevin this is just lovely. I also love how there is an intuitive unterstanding of x and y in this graphic without any explanation :D Also wow the internet was down for half an hour. pcl docs were also down :P
 
12:37 PM
Pointless combinatorics problem: there are 4,861,946,401,452 ways to combine 25 left square brackets and 25 right square brackets into a balanced string of brackets of length 50. If you put all these strings into a list and sort it, what is the 1,000,000,000,000th element?
 
12:51 PM
So that's the language of strings like [][[]]?
 
Yeah.
 
And you want to sort by ascii value, i.e. '[' < ']'?
 
@Kevin I think the issue at that point is the more distributed it becomes, the more it becomes weak to distributed attacks. It's like a naval arms race, but instead of inventing silly big dreadnoughts, you're inventing silly small things that can vomit over Ethernet.
 
1:29 PM
@MisterMiyagi Yes, although I will also accept solutions that assume "]" < "[", since I believe the problems are isomorphic
I suspect that "finding the Nth-in-order string of length W" has a big O complexity that's dominated by W far more than N. So it ought to be fairly cheap to find the (4,861,...,452 - 1e12)th element, compared to finding the 1e12th element.
The algorithm I have in mind is something like O(log(N) * W * log(W))
 
1:44 PM
Wondering whether it's possible to formulate something like a counting system from the language. E.g. for length 6 '[][][]' is the largest and '[[[]]]' is the smallest, with '[][[]]', '[[]][]', '[[][]]' inbetween.
The closing ] are a visual red herring and we could rewrite that as [_[_[_, [_[[__, [[__[_, [[_[__, [[[___. In essence, one can just left-shift ['s without bothering about matching ] via nesting – as long as the overall count fit's that's enough.
 
I can't even figure out a not-stupid way to generate all combinations, much less a specific one
 
2:06 PM
I have a way that generates all combinations (pastebin.com/2JjymiyH), and I thought it generated them in lexicographic order, but it outputs results in a surprising order at around num_pairs = 4
ideone.com/WSdDWv shows how the first four rounds are OK, the next round has a single error, and the following rounds become increasingly disordered
I think this torpedoes my O(log N W log W) idea... I am sad
 
Figured out my own way of doing it, seems to be sorted too as far as I can tell
 
Kevin - have you thought about creating your own Advent of Code? Kevin Kevinsson's House of terror funpuzzles
 
I could probably manage to produce 25 good puzzles a year, if I try real hard. But then I wouldn't have any good puzzles left over to share in here ;_;
 
Paying jobs are overrated anyway
 
2:21 PM
@Aran-Fey Looks good to me. I like the idea of building the string in strict left-to-right order, which is not exactly what I'm doing.
 
I am genuinely starting to dislike windows the more I realize you have to work around it to use certain packages and libraries -,-
 
Devil's advocate: I genuinely dislike packages and libraries that aren't compatible with Windows
 
Lol fair enough just referring to the likes of lib_postal installed it and got working on the linux one in a matter of 10 minutes and windows having to work around it a lot to get it working
 
Did you try asking nicely?
 
If this is a roundabout way of getting Windows fanboys to defend their OS' honor by giving you step-by-step instructions showing how easy it is to get lib_postal working, nice try, but that only works on Linux fanboys.
 
2:33 PM
@Kwsswart I have heard docker is useful for this, easier to manage
 
Windows is my terrible ugly baby and I don't need to deny its flaws
"Thanks for calling Kevin's tech support. Have you tried accepting the fact that being broken is any system's most natural state?"
Try turning your preconceptions about the inherent value of negentropy off and on again
 
TIL about negentropy
 
2:52 PM
Folks, what is the topic name for double output in the following?

_, frame = cap.read()

I want it to be fed into Google for searching.
 
Tuple unpacking?
 
Unpacking Iterables?
 
Here is a balanced parens iterator that prints all valid strings of length W, in order, using only O(W) memory. In other words, it only needs to store the previous string to find the next one.
Oops, I accidentally left out the last line, <four spaces>last = s. The output is still the same though, since last is just for verification
 
@python_user may take a look into it tomorrow heads fried for today lol
 
3:08 PM
I was hoping that typing this out would give me some ideas for advancing forward more than one value at a time. But I don't see anywhere to stick a super incredibly good optimization. Alas.
 
late morning cabbages, folks!
 
Maybe I can do something with caching...
 
folks, optimization question:
I have a list `L`, of triples `(a, s, e)`. `a` is any object and is irrelevant to the problem. `s` and `e` are floats that describe a subsegment in [0,1] (eg: a=0.032123, b=0.042314). It is the case that L[i+1]'s `s` is equal to L[i]'s `e`. L is sorted by the `s` values. Given a random number `r` in [0,1], I want to find the `a` such that `s <= r <= e`. My current solution is a non-recursive binary search. Is there a way to make this faster (say, with a trie)?
 
I think it's always true that next(A+B+C) == A + next(B+C) for any balanced paren strings A, B, and C. Quite a lot of balanced paren strings can be decomposed this way, so maybe that's helpful for a divide-and-conquer approach
 
s, e, r are of arbitrary precision. r is generated by random.random, so lru_cache probably won't do much
 
3:18 PM
@inspectorG4dget I'm pretty sure the best you can do is logarithmic performance, but I wonder if you can do better than log_2 performance...
 
oh damn! Good call. I could parallelize and get log_2(p-th-root) performance
 
hi
python manage.py runserver
 
If you think of each triple as a slice of the number line, are the sizes of the slices all about the same? If not, Maybe you can improve average case performance by trying to split the list into equal "widths" rather than "lengths" each time you narrow down your search window
 
the slices are very not the same. I should have mentioned this earlier - it's a search in a roulette wheel (the kind you'd use for a genetic algorithm)
 
Incidentally, random.choices is often the fastest approach for problems relating to roulette wheels with unequal sized slices
 
3:29 PM
this is brand new information to me. Thank you. I'm probably going to implement this
 
I wonder what it's doing under the hood... I'm guessing it's something in the neighborhood of the designs we were kicking around
Let's see... It's using bisect.bisect, which is just regular old binary search. So maybe it is worth implementing a fancier "even-width" search, since it can shave off a couple iterations for very clumpy weights
 
A binary tree would pretty much achieve that, right?
Although it'll be hard to outperform the C implementation of bisect...
 
Yeah, a binary tree works. And you can build the tree once and make use of it multiple times for consecutive random trials. I'm trying to decide if the tree is conceptually equivalent to a trie, but I guess it doesn't matter a whole lot either way
 
At the end of the day, what matters is that it's a tree
 
3:45 PM
"C implementation of bisect" -- oh, I only looked at the Python one. Maybe the C one has fancy width trie search...
 
Hi everyone, does anyone have experience with pymongo? In that specifically I am having trouble when I am deleting documents. The intention is to free up all the space when doing that but when I use a normal CRUD operation it doesn't delete the indexes which are by default the primary keys(_id field). Does anyone know how I can do this programmatically?
 
bisect.c uses binary search, alas
I guess optimizing for chunky roulette search either 1) makes other more common cases slower; 2) requires information about the higher-level problem that bisect isn't privy to
Kind of what I figured, but you never know when there's some TimSort-level brilliance hidden away somewhere
@RaphX In your opinion, do you think the problem is with pymongo, or with MongoDb? Does the problem still happen if you talk to the database without using Python?
(Not a trick question; I promise not to say "go ask somewhere else please" if you think it's more of a MongoDb problem than a Python problem)
 
4:11 PM
@anky Thanks Anky I'll look into this!
 
@RaphX you mean compact?
 
hello!
This is my first time in chat!
 
4:27 PM
Hello :)
 
yeah sort of I guess, @roganjosh but I am not able to use that programmatically
not sure @Kevin , trying to find that out :)
tried this command @roganjosh
db.command({'compact': 'inventory'})
However I got this error which is not returning any matches using google: OperationFailure: CMD_NOT_ALLOWED: compact, full error: {'ok': 0, 'errmsg': 'CMD_NOT_ALLOWED: compact', 'code': 8000, 'codeName': 'AtlasError'}
 
folks, do you know how to create a raw array as a mat to be displayed on the window?
import cv2
import numpy




frame = numpy.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]], [
[128, 0, 0], [0, 128, 0], [0, 0, 128]]])


cv2.namedWindow("camera", cv2.WINDOW_NORMAL)
cv2.imshow("camera", frame)
 
@RaphX No matches, or no useful looking matches? If you got literally zero results, I wonder if that had anything to do with the CDN outage this morning. When I search right now, I get results like stackoverflow.com/questions/45663890/…
@TheShortestMustacheTheorem A raw array as in, the kind of arrays you usually find in C? I guess the closest thing Python has to that in its standard library is array.array.
 
4:42 PM
yeah but its related to mapreduce, not sure whether it applies to compact as well @Kevin
 
I am also not sure.
 
@Kevin Hmm... I don't understand.. Trying to figure out with GOOGLE.
 
Excellent. The more you know about your desired goal, the better i can help you get there.
 
I want to create an 3x2 array of pixels as follows:

[[[255, 0, 0], [0, 255, 0], [0, 0, 255]], [
[128, 0, 0], [0, 128, 0], [0, 0, 128]]]

I want to display on the window.

A simple goal.
The problem is I don't know how to feed this array to opencv function imshow. The format might be wrong.
 
Ok, sounds reasonable
I also don't know what the format should be. Google is not giving me useful documentation.
 
4:49 PM
@Kevin: OK. I am leaving for a couple of hours to figure it out myself. Thank you very much!!!!!!!!!!!!!
 
does this work?
 
I found out the thing I was looking for @Kevin
Also learnt that sometimes unrelated things can lead to something related
 
Wisdom
 
@TheShortestMustacheTheorem and @Kevin make sure if you make the numpy arrays by yourself you feed opencv an array thats either a float64 or a uint8.
 
OpenCV's documentation needs work because it says that imshow takes an InputArray, which is an alias for Mat, Mat_<T>, Matx<T, m, n>, std::vector<T>, std::vector<std::vector<T> >, std::vector<Mat>, std::vector<Mat_<T> >, UMat, std::vector<UMat> or double. I don't see "numpy array" in that list --
 
4:58 PM
it's not smart enough to handle other dtypes unfortunately. and the errors it throws are exceptionally bad if you end up with that scenario
 
-- but I trust Paritosh and his link that say that it works anyway, so the documentation must be somewhat less than totally comprehensive
Perhaps the broader issue is that the page does not discuss Python types at all.
 
aye, opencv documentation itself isn't particularly friendly. this is one scenario where i'd suggest using other sources for python specific advice
theres a blog site called pyimagesearch that was specifically very useful at working with opencv
 
docs.opencv.org/3.4/d3/d63/classcv_1_1Mat.html indicates that Mat is "compatible with the majority of dense array types from the standard toolkits and SDKs, such as Numpy (ndarray)" and many other types that represent their data in a "dense" form. If I understand what "dense" entails, then array.array is also a dense type.
 
hm, ive never tried to use array.array with opencv... or array.array with anything, but that's minor details. :P
 
None of this tells me precisely what form the dense type needs to be in -- can I give it a plan old address pointing to the zeroth element, along with the stride sizes of each dimension? Do I need to pack all that into a header? It is a mystery
I'm open to the possibility that the documentation does answer these questions, but I lack the C++ experience necessary to understand. It be like that sometimes.
 
5:25 PM
@ParitoshSingh Only talk about zero array that is not my case. Thank you!
 
uhm, that's just a sample code. you're supposed to modify it as you see fit.
if the snippet with the zeros work, then you'll know that the snippet can be built upon
 
@ParitoshSingh glad to see my pyimagesearch evangelism is working ;)
people never used to talk opencv here, now it's all the rage
 
That sample code displays a black rectangle. I want to display a red rectangle, with a blue outline. We need to keep searching for example code that displays a red rectangle with a blue outline.
"modify it as you see fit" -- but how can I be sure that a piece of code is functional if I didn't find it online? Seems a bit risky tbh :-/
 
haha, great risk, great reward. ;)
 
It is okay to search for regex code snippets that perfectly match your use case though, right?
 
5:39 PM
They say its the journey that counts, not the destination
 
Returning to actual advice mode: sure, search for those snippets. Just use your best judgement to decide which is the best use of your time: making your own solution, or looking for an existing one.
For imshow()ing nested Python lists, I estimate that it would take about thirty minutes to make your own solution by playing around with ndarray until you get something that shows sensible output. Since Mustache spent more than thirty minutes hanging out in here waiting for advice and/or examples from us, I was poking fun at the fact that this is not an optimal strategy
 
Hanging out here is probably never optimal strategy, although quite enjoyable
 
But perhaps I am being uncharitable by assuming that he was not also experimenting with ndarray and such at the same time. Spending ninety minutes gathering advice in chat is only suboptimal if you're sitting there twiddling your thumbs
 
6:15 PM
Hello, Android!
 
@Code-Apprentice Android?
 
lol...wrong room
cabbage then =p
I hang out in the Android room, too...although I do no android programming any more.
but I got your atttention ;-)
 
@Code-Apprentice We've just defined this as suboptimal behavior when trying to solve problems :) But, no code, no problems
 
I was catching up on some of the recent conversation...since when do we hang out here for "optimal behavior". I never realized that was even a thing...
 
My thoughts exactly
 
6:20 PM
Quick question - I'm trying to understand where and when an integer is parsed and the Python compiler translates it to a PyLongObject by changing it base to 1 << 30 (or 2 ^ 30). Can anyone plz suggest where the integer is converted from a string to PyLong?
A link to post which explains would also do.
 
Are you looking specifically for how Python parsers and then compiles source code, or just how it would handle int(some_integer_literal)?
 
The second one
 
6:38 PM
@MisterMiyagi So Python parses the integer and then passes it to PyLong_FromString?
 
Oh man, letting a program take control of your mouse cursor is always fun, no matter how many times you do it. I still have some bugs to squash, but I'm already all giddy with anticipation. (I'll have it draw a bunch of 50x50 images for me)
 
wim
@AnttiHaapala regarding __init__.py for resource loaders, afb2eed reverts CPython to using a plain old subdirectory instead of subpackage for those vendored packaging wheels
 
@ShreyanAvigyan I don't understand what you mean. PyLong_FromString handles the parsing of the integer.
 
@MisterMiyagi It parses the string passes to it right? Well at least the docs say so.
I wanted to know how Python converts the token NUMBER to a PyLongObject
I couldn't find any references.
 
Ah. So you wanted the first one, not the second one.
 
6:52 PM
Good luck finding the relevant code for that
 
import cv2
import numpy as np


frame = np.array([[[255, 0, 0], [0, 255, 0], [0, 0, 255]], [
[0, 0, 0], [255, 255, 255], [128, 128, 128]]], dtype=np.uint8)


cv2.namedWindow("camera", cv2.WINDOW_NORMAL)
cv2.imshow("camera", frame)

cv2.waitKey()


Problem has been solved by Dan Marsek. :-)
 
@Aran-Fey That's the problem. I can't find that code.
It would be really great if someone could share a link to some post that explains it or someone explained it by themselves.
 
wim
That would probably be in ast
it's still a NUMBER token after tokenizing
$ python3 -m tokenize <(echo "0xff")
0,0-0,0:            ENCODING       'utf-8'
1,0-1,4:            NUMBER         '0xff'
1,4-1,5:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
but already an integer value after ast parse
$ python3 -c "import ast; print(ast.dump(ast.parse('0xff')))"
Module(body=[Expr(value=Constant(value=255))], type_ignores=[])
so, I guess you would want to look in Python/compile.c
 
Thanks so much. The AST codebase is really simple to look at. I have already looked in compile.c and it's not there. But I now know where it is located. Thanks!
 
7:13 PM
Hi
 
@ShreyanAvigyan I guess this has something to do with it?
 
7:29 PM
github.com/python/cpython/blob/… looks rather string-to-int-y, but I'm not sure where pegen.c fits into the tokenizer/parser/compiler structure. And that's assuming that it even gets run
 
This delving into the source has been a bit of a rollercoaster. I've gone from feeling like I really need to learn C to just being overwhelmed with the complexity of this
 
7:44 PM
@Kevin tokenize.c generates tokens -> pegen.c creates AST nodes from the tokens -> compile.c creates a CFG temporarily and then creates bytecodes -> finally ceval.c executes the bytecodes. Although the line you linked actually is a part of the whole thing I want to achieve. 50 % complete. Another 50 % to go and I'll soon find how integers work!
 
i have a list with user-defined 'n' elements[string]. my program ports the list of strings to list of corresponding objects.

Now how to give a unique name to each of the object in the list regardless of duplicates? and callable.
previously i built a dictionary with incrementing integers. But i now need better implementation, i am stuck because objects can't be named in integers.
 
Don't give them unique names. Not all objects need to be variables.
 
@Kevin i felt calling them as obj1 and obj2 is easier in the later part of the program
 
@PIngu Why does each object in the list need a unique name? Can't you just index them in the list?
 
7:48 PM
Nope, it won't be easier. I've seen a hundred people try this design, and I've seen zero people that wound up happy with it.
 
@Kevin hmm, noteworthy
@Code-Apprentice during the later half of the program i find it very messy to call objects by index no, say for instance list[no] and list[no+1], because more previous and next callables are required
 
@PIngu more messy than obj1 and obj2, etc.?
 
@Kevin so you recommend that i stick with list indexing ?
 
Yeah
 
also there is no way to generate a variable name from a variable value*
 
7:52 PM
@PIngu So how would you access obj_no and obj_no+1?
 
You might find hacks involving the semi-private dictionaries that Python uses to store variable names, but the docs assert that you can't depend on them being modifiable, so your code could break tomorrow if they decide to change some implementation details around.
 
@MisterMiyagi that brought me to where i began, hahaha. I previously implemented a dictionary corresponding to list, with keys being integers (identifiable by their position in the list)
now that i am wanting to build objects, rather than objects tied to dictionaries
 
So how are objects tied to names better than objects tied to dictionaries for your use-case?
 
I don't think I follow what you're trying to so. Can't you run the string through SHA256 hashing and use that as keys to a dict?
 
00:00 - 20:0020:00 - 00:00

« first day (3888 days earlier)      last day (1054 days later) »