I ate the chip quickly. It burned my lips, throat, tongue, and more... for five minutes. I felt dizzy, then euphoric. After 10 minutes, I felt fine. For the next 24 hours, every 3 hours, I needed to excuse myself from the room /-:
So, I found an interesting performance bottleneck but I can't quite find the function to fix it. foo=np.argwhere(big_array == value)[0][:small_number] where big_array is a few terabytes and small_number is like 7. Is there something like "find first n elements?
to be clear, you want an efficient way to do this:
def firstnonzeros(a, n):
k = len(a)
index = 0
counter = 0
indices = []
while counter < n and index < k:
if a[index] != 0:
indices.append(index)
counter += 1
index += 1
return indices
firstnonzeros([0, 0, 0, 1, 1, 0, 1, 0, 1], 2)
# [3, 4]
I was hoping to leverage this Q&A but it requires you already have a boolean array after having evaluated myarray == myvalue which defeats the purpose.
Sorry, I don't see any other way than just looping.
For completeness, I would have suggested repeated calls to argmax on the boolean array.
If you do it outside rather than making wrapper functions in a wrapper class you eliminate more than 50% LoC. If they were doing something more it might eventually be worth it, but all the above code really does is rename existing functions in a verbose way.
Yeah, just using those functions directly is the easy way, unless you legitimately are doing additional work in the class and functions you're writing. C.f. lambda x: len(x). :P
Not just conversion; any single function. The expressions that actually do the work, np.asarray() and pd.DataFrame(), have just been moved elsewhere. You'd still need to write them at some point or another either way. The my_list.to_numpy() way isn't even shorter. You could perhaps do n = np.asarray etc. if you plan to refer to those functions frequently.
@python_user seems like a good use-case for functools.singledispatch. That is assuming you need to do this for more than one type and more than one implementation.
On another note: How are people handling linters/checkers/tests for contributors in their repos? We always have the CI check everything, but are unsure how much to put into pre-commit or pre-push hooks.
Right now we're either "everything in pre-commit" or "nothing in pre-commit" but neither is satisfying. The pre-commit route is a bit heavy and often times I'd rather have people commit partial things instead of finishing them – TTD comes to mind. The unchecked variant allows much smaller commits but often requires fixups.
Hey guys anybody got any knowledge on how to get flask mongoengine to connect to a mongoatlas cluster? I have tried setting the host to the corresponding cluster uri but not connecting
@MisterMiyagi that's something that always comes up in my projects as well. Currently we do "no pre-commit" everywhere and just document the toolchain, for the reasons that you also gave. We squash feature branches, so messy commit history doesn't matter.
Is there a VCS where a "branch" is not just a particular commit, but rather a series of commits? With git, you create a feature branch, make some commits in there, and then you can either merge all those commits into master, or you can squash them into a single commit and merge them into master. There's no way to leave the feature branch as-is, but only make one commit to master, is there?
I should probably check out some of the git workflow tools people have made, like gitflow or whatever it's called. Squash-merging every feature manually sounds like a pain
Hmm, let's see if I can explain this. Basically, it's about granularity. I want every commit to master to be a complete feature/bug-fix/whatever. But in reality, while you're developing that feature, you're gonna make a whole bunch of commits. I don't want to lose those, but I don't want them to show up in master either. So every feature branch would need to be squashed, then merged into master
@Aran-Fey If you are managing the repo via GitHub/GitLab, you get the entire icky parts wrapped by a very nice and useable GUI. I basically only do git add/commit/tag/branch via the command line. The rest is exclusively via GUI; feature branches are always eventually a Merge/Pull request and squashing them is a click of a button.
I think I might write a small command line tool that does all the branching/merging for me, maybe even auto-update the version number while I'm at it...
@Aran-Fey OK. So you don't even need an auxiliary branch.
The way you use it is git checkout master; git merge --squash feat; git commit, after which you can edit the squashed merge commit message. The original feature is left intact.
Alright, I'm definitely automating this. What's the consensus on keeping old feature branches around? I'm worried that'll create too much clutter in the long run
I found the BITS(https://biosbits.org/) project, which stands for Bios Implementation Test Suite. The creators managed to allow python to access low level functionality of hardware and run directly without relying on a separate OS. As it is written on their website's homepage:
> BITS supports scripting via Python, and includes Python APIs to access > various low-level functionality of the hardware platform, including > ACPI, CPU and chipset registers, PCI, and PCI Express. You can write > scripts to explore and test platform functionality, using the full
Well, yeah, of course they're all assembly and C. That's the only sane choice. That doesn't mean you cannot do the same in Python (minus parallelism, perhaps) but you will be interfacing with things that are only talked about in assembly/C terms.
Quick one: how can HTML attributes be passed to {{ wtf.quick_form(form) }} when working with flask-bootstrap and flask-wtf. Technically, the documentation states that the use of {{ wtf.quick_form(form) }} is best for creation of forms on the go (I mean very quickly). However, to have more control, manual creation of forms is recommended.
I understand that, but I trying to pass HTML attributes such as id and class to a form using the method {{ wtf.quick_form(form) }}. This how the forms can be made dpaste.com/F97SJT3JF
Is it achievable? I have found out that key words can be passed to a form as follows: `username = StringField('Username', validators=[DataRequired()], render_kw={"placeholder": "Username"})`.
It would be great to add a class or an id just like placeholder. but apparently that does not work
I haven't noticed anything strictly saying it is not on-topic in SO either.. but that's my general idea. :) you can check this: meta.stackexchange.com/questions/211788/…
You're on Stack Overflow and you've found a question that seems to be about improving code. You are trying to be helpful, and you put a comment in the question:
You should try asking on CodeReview.SE instead. —YourName 2 minutes ago
… and suddenly, out of nowhere CodeReview.SE users swoop i...
that would make sense, I did not even know there were other sites when I started college, I thought the other stackexchange sites where fakes of SO for different topics :D
Yes I have seen them do that before so I try not to blanket refer to CodeReview. Why does the Close because it belongs on another site option only have four sites listed?
So the A guide to Code Review for Stack Overflow users on the CodeReview meta is pretty straightforward - Codereview is just that more of an open ended Q&A asking for generalized critique.
A while back, months/weeks, I got a pop-up survey on how I perceive down-votes. Was that most likely a random selection or a result of my liberal down-voting?
Specifically what I think it means when I down vote.
Although I have to say that reading on meta does inform me even when there are highly up-voted conflicting answers/opinions. re: Internal search is useless .. use search terms site:meta.stackoverflow.com?? Oh yep first answer.
It's time for Vague Questions: I have a vendor that has delivered a python API via pyc files. The problem is, I can't install these into other environments with different versions of Python. What is a simple workaround to make those API calls available to a new updated Python env? If a simple workaround isn't available, what is any workaround?
Should I write a goofy wrapper that takes re-creates the API and makes system calls? Should I try to reconstruct the py files from pyc files and install in the new env?
how can I increase the speed of this algorithm ? maybe use some vectorized stuff?
def find_shortest_path(self, start, end, path=[]):
path = path + [start]
if start == end:
return path
if not start in self.graph:
return None
shortest = None
for node in self.graph[start]:
if node not in path:
newpath = self.find_shortest_path(node, end, path)
if newpath:
if not shortest or len(newpath) < len(shortest):
shortest = newpath
return shortest
This might not be the best place for it, but since it’s somewhat connected to Python, has anyone here worked on NLP in the context of application testing?
I mean I found a better approach but I got the eroor
TypeError: 'int' object is not iterable on the q = deque(start) line
def find_shortest_path_liniar(self, start, end):
dist = {start: [start]}
q = deque(start)
while len(q):
at = q.popleft()
for next in self.graph[at]:
if next not in dist:
dist[next] = [dist[at], next]
q.append(next)
return dist.get(end)
Since you asked... Relieved and annoyed both at the same time. Relieved because my new motherboard came back from its BIOS update and actually works with my new CPU now, and annoyed because that means I have to reinstall everything on the new PC
...and first, I have to backup my data over a 100KB/sec wifi connection
My ethernet stopped working recently, no clue what's up with that. But I could temporarily move my PC to my brother's room (where the router is) I guess
For now, my plan is to hope that not much changed since the last backup, so it won't have to transfer too much data
Nope. My only hope for LAN is a powerline adapter, but it's refusing to cooperate
Plan A: Patience. Plan B: USB tethering via my phone. Plan C: Moving the PC closer to the router. Plan D: Losing all the data that changed since my last backup
@GretchenRichards Instead of pinging people randomly, your time would be better spent providing more details about your problem. If someone can help, they will. If not, your pinging won't change that.
Neither of which are really relevant to the error that you have got. You need to show the code that raises the error with an MCVE as asked. Please also see the room rules though before posting
@CătălinaSîrbu Floating-point numbers can't represent all decimal values exactly; the trick is to use formatting techniques to display the numbers to the precision you want. If you're familiar with the f-strings, you will find that after g = 11.720000000000001 the expression f"{g:8.2f}" evaluates to ' 11.72'.
An older equivalent is` "{g:8.2f}".format(g)`, which does the same thing in a more verbose but backwards-compatible way.
not according to that link (unless I misunderstood). Evidently, if a query left the db in some error state, a subsequent query might cause such an issue. That being said, I've been able to run the error-observed query independently and it works
@inspectorG4dget I don't know databases, but to my layman's eyes it seemed to say "every subsequent query will raise that error" but it doesn't say whether the original failing query will raise it. If I were designing a library I might tell the user that subsequent queries will be ignored right when the failure happens.
how could I do a regex in vscode to select them. I was trying `def.*(.*):[\n+\s+\W+]+.*logging to see if i could get there but this doesnt do a greedy matching
I have a lot functions i've just been asked to reorganize and i thought itd be interesting to select them all at once
@AndrasDeak that seems very logical, but "This is what postgres does when a query produces an error and you try to run another query without first rolling back the transaction". My interpretation is that what causes the traceback on stderr is the "another query". In the try-catch, a `cur.execute("select 'hi'") fails. Am I just missing something super obvious?
If "a lot" is several hundred, maybe look for an automated solution, but if it's thirty, it will probably be quicker to manually search them out and edit them. I speak from experience ...
@inspectorG4dget I just don't take such claims without citations for granted. You never know if the person just phrased it sloppily, or was plain wrong. The question doesn't focus on the number of errors, it's just "I keep seeing errors", "yeah, you have to roll back first". Just my general caution toward anything I read online without convincing proof. Because my premise is that what you see contradicts the answer. Either you're wrong or the answer (or our interpretation of it) is.
@holdenweb yea, had to do this for like 60 or so functions before and I made it work once, this time its just 28 functions across a few files im just annoyed at myself for forgetting
i can get an easy compromise of semi manually doing it by just doing def.*(.*):
what is good write-to-db architecture? should I create a cursor once and pass it to a function to write each of many queries? or should I let the underlying function create a new cursor for each write?
ok so it looks like there was an issue with some query not fully committing. I enabled autocommit on the connection, and that solved the issue