« first day (3508 days earlier)      last day (1439 days later) » 

12:00 AM
Clever idea to search the character in String than a tuple.
The exercice is about one single charactec for doing math calculation. So it will work too
 
12:17 AM
oh wow
 
if only someone could single-handedly close that :P
the html title is fitting, though
 
I'm too busy being in shock :p
 
Advice from a fellow German:
- don't use non-english for identifiers (and anything else that's not a user-facing string). it looks weird :)
- PEP8 prefers `snake_case` for identifiers
 
hey @Thief - how you been?
 
that's not CamelCase; that's just German ;D
 
12:25 AM
fine :)
 
Thiefmaster You mean by identifiers the variable names like Rechenart?
 
I'd forgotten how good (imho anyway) "The Score" album was by the Fugees...
 
 
12 hours later…
12:32 PM
front-page definitely looks more modern... the docs don't look any different?
 
it's still under construction I think
> Next, the NumPy web team will focus on updating graphics and project identity (a new logo is coming!), adding an installation widget and translations, better integrating the project documentation via the new Sphinx theme, and improving the interactive terminal experience. Also, we are looking to expand our portfolio of case studies and would appreciate any assistance in this matter.
I suspect that "sphinx theme" integration might also affect how it looks
 
ahh... new sphinx theme... that should be interesting
 
user11702787
12:52 PM
about this function / replaces values of a list of list with new one
 
user11702787
def insertdata(data):
    data_added = False
    n = len(listoflist[0])
    index = 0

    while not data_added and index != n:
        if listoflist[0][index] is None:
            listoflist[0][index] = data
            data_added = True
        else:
            index += 1

        if index == n:
            print("\n The list is full, No more elements will be added \n")
 
user11702787
why does the loop continues if ` data_added = True` gets executed ?
 
user11702787
should the loop not break ? while not data_added and index != n:
 
user11702787
never mind got it
 
is there a reason why you don't use a for loop for this?
for idx, element in enumerate(mylist) is usually more robust than while loops
just doing listoflist[0].index(None) to get the index is probably even simpler (and faster), though
 
1:15 PM
could anyone please help with the python regex?
 
@Suri not if it's your fresh question on the main site, as per our rules.
Please wait another day and a half before asking us to help with that
 
ok
 
2:18 PM
I have a db column name as model that stores values from html select option let's say I store the values as abc, abc1, abc2 in different entries to the db, but the reason I am storing these as abc is because I don't want to unnecessarily store long names in db. So I have to map these abc, abc1 to real world long names which likely will remain the same like ashwinp, ashwinppp respectively for abc, abc1, is using dictionary the right approach for this or should I use lists instead?
 
storing them in the DB seems like the right approach.
 
Oh , okay.
 
But yes, if you want to map names, a dict is appropriate.
 
I almost completed writing pastebin for example lol
@MisterMiyagi I am now confused.
 
@AshwinPhadke Consider how much you are storing versus how much you are saving. If you are using a DB, you are likely storing lots of entries which all share the same column names. Having the long names in there is only little overhead.
 
2:25 PM
@MisterMiyagi oh okay, I guess storing in db is making sense now as the names would remain same in the select tag of html.
Also now that I think of it if I make a dictionary I then have to get the value for it thus increasing time, am I correct? @MisterMiyagi
 
you can edit/delete messages for 2 minutes in chat
 
@AndrasDeak did it.
pastebin.com/D32HDUSR here's the pastebin if required.
 
@AshwinPhadke Yes. Applying a mapping in Python for each entry is most certainly slower than not doing a mapping at all. In case of doubt, even doing a mapping in the DB is likely faster.
 
Concurrent, Parallel and Distributed programming in python. Can anyone please tell me the benefits or direct me to a good source.
 
2:43 PM
@AanuBabajide That's... a bit broad.
The benefit of concurrent, parallel and distributed programming is that you get concurrent, parallel and distributed programs.
 
@MisterMiyagi Indeed, but I really want just a broad overview of the difference between them? Once I get that, I think I can find suitable materials around.
 
Did you check wikipedia, then?
I've also stumbled over this "Concurrency Glossary" article while looking for other things, and it seems reasonable. Might want to take a look.
3
 
@MisterMiyagi okay thanks, quick thing, whatever the value stored in the column is , the corresponding file has to be fetched from the directory.
 
 
2 hours later…
4:42 PM
There was a question I seem to have lost asking how to find all words that "nearly rhyme" with an input word, i.e., war and cord. I think it was in Python but not 100% sure. Has anyone seen it?
 
Have you checked down the back of the couch? That's where most stuff seems to be when I lose things :p
 
:P
I think I bookmarked the subject it suggested to search then deleted the bookmark.
 
Well: site:stackoverflow.com rhyming words python in a google search seems to get a few hits...
 
Ohhh, that'll work, my search terms were too specific. Thanks!
 
 
1 hour later…
6:01 PM
hey..anyone here?
 
maybe...
 
needed a little help with my python code
 
Okay - would you mind having a read through the room rules in the top right please? It's got some guidelines on how to ask and code formatting and all that :)
 
is it ok if i paste a 'pastebin' link?
 
6:05 PM
ok
i'll explain a little beforehand
i was reading about Knights Tour problem on geeksforgeeks
i tried visualizing the same using pygame
the runtime of the code from geeksforgeeks website as is - is around 25-35 seconds
but when i tried visualizing using pygame its taking forever
here's the code - i've commented out the visualization portion - uncomment it to see the run time difference
 
Can't say I'm surprised. Without the visualization, each "step" in the simulation is a bit of simple math. With the visualization, it's more math + rendering. It's basically like the difference between counting to a million and counting to a million while printing every number.
 
Perhaps you can take that 25-35 seconds, record only the state changes that you want to visualize, and then just visualize them separately.
 
6:30 PM
i think i'm doing the minimal visualization
and does that mean there's nothing wrong with the code that i have written?
 
not as far as I can tell, at least
 
any wild guess as to how much time it would take to complete?
i5 4200 8gb ram [i dont even know y im asking]
 
no clue
 
6:56 PM
i'll get back with an answer
 
you might want to opt for just drawing the board on the terminal.
works much faster.
as far as I can tell (only got it to work on 4x4), you basically draw the same thing again and again and again. Yet, the code recreates both information and objects every time.
Consider to use pre-computed fields, similar to an object pool, and just toggle them on and off.
 
1. ran it for 23 mins with no result
2. tried doing it this way thinking it will visualize things, might look pleasing
3. thnking only drawing/redrawing elements every 5 or 10 seconds
4. might use a better algo
can anyone suggest a way that i could redraw board every 10 seconds?
---
The Hamiltonian path problem is NP-hard in general. In practice, Warnsdorf’s heuristic successfully finds a solution in linear time.

Do you know?
“On an 8 × 8 board, there are exactly 26,534,728,821,064 directed closed tours (i.e. two tours along the same path that travel in opposite directions are counted separately, as are rotations and reflections).
 
7:14 PM
Have you considered not solving an NP-hard problem?
Back to your problem: it seems PyGame does not mind having other threads run alongside. So, have a separate Thread that triggers drawing the current board every t seconds.
Re-drawing the board only every n attempts might also help.
 
7:35 PM
hehe..thought it would be fun sunday project
 
Hello,
Is there any way to change text colour of all Tkinter widgets?
import tkinter.font as TkFont has no colour parameter.
 
8:12 PM
FYI, after much struggling I found a one-line commandline way to report Python major,minor version, buildlevel:
> python -c "import sys; print('{}.{}.{}-{}-{}'.format(*sys.version_info))"
3.7.6-final-0
Because you can't do python -m sys, sys isn't executable module. Also, it occurred to me that one thing .format() still has over f-strings is when you want to specify different separators, and/or other arbitrary chars in the format string.
 
8:46 PM
Can anyone help me to get Python to import modules from non-conventional locations? I've tried updating the sys.path and adding empty init.py files to subdirectories but it's still not working?
 
8:56 PM
@JamesMcIntyre please don't ask for help here with fresh questions on the main site, as per our rules
 
I'm sorry Andras. I genuinly didn't mean to break the rules.

Just seen that rule there. Apologies.

To clarify. If I hand't asked that question on the forum, I could have asked the question in this chatroom?
 
Yup. The point is that we don't want to have fragmentation of information, so discussion should be in one place only. If you're stuck on the main site after 2 days, feel free to ask. And conversely, if you ask here first but don't get the help you need, you can ask on main.
and it's alright
 
@AndrasDeak Thanks Andras. Does the 2 day rule apply both ways? I.e. is that the appropriate time to wait if I asked the question on here before asking on main or would that be shorter?
 
@AshwinPhadke This was a while back, but using abc and abc1 is a problem. You mention models so I assume it's a django (possibly flask) app. In that case, you just want an INTEGER PRIMARY KEY to identify rows, which can auto-increment. Miyagi was correct that it should all be stored in the DB but you should think about how you want to do joins as your site gets more complex
 
@JamesMcIntyre there's no clear-cut rule, mostly because we can't enforce anything you do on the main site :) My idea is that one asks here, takes part in a reasonable amount of discussion, and either solves the problem or clearly ends up in a dead-end. Or, more likely, the technology is not used by anyone who can help (or who is willing to help), in which case the lack of responses for a longer while can make one ask on main. But as the above make it obvious, there is no hard rule in the other way.
 
9:12 PM
@AndrasDeak Thanks again Andras. I'll try and bear this in mind
 
@AshwinPhadke the primary key will be a "sequence" (at least in Postgres, it's possible that other terms will be used in other technology), the same as an index. The database will remember the last id that was assigned, so deleting rows will not result in conflicting primary keys
 
Thanks :)
as a general suggestion, chat is a bit more active on weekdays than on weekends
 
@JamesMcIntyre One thing to note in regards to my comment. Don't feel pressure to accept edits that get suggested. You were right with your tags the first time. Had I actually reviewed the edit, I would have rejected it. The original poster can accept edits outright, though, so you potentially skipped a process that might have thrown the (bad) suggestion out and given your question more visibility
 
I think post owners can also retro-actively reject edits, but that might not be an option when they accepted in the first place
 
I'm sorry roganjosh. I don't understand how my acceptance of the edit reduced its visibility?

I think I understand why the OpenCV tag is incorrect as it's not really about OpenCV (the editor seemed more experienced than me so I took her word for the tags) I don't understand how accepting the edit reduced my visibility though?
 
9:20 PM
@JamesMcIntyre I spend a whole lot of time on the "main feed" normally. This is what I'm referring to, if I ever mention "main". Once you dropped the and just went with the version-specific tag, I would never see it
 
They took away your main language tag, which is always a mistake. Python code must have .
 
Thanks guys
 
9:44 PM
Hi guys, I am very new to Python. Is it possible to optimize my code below?
 
<deletes half-typed message> Cool. No interest in participating. A drive-by "solve-this-for-me"
 
It's like the epitome of Neg's Burger Bowl Off especially as the money racks up with the more burgers thrown
 
Is it wrong to say "ping me" now?
 
No, it's very bad form to say "hey guys, help me with <thing>, ping me when you're done" and then leave immediately.
 
9:53 PM
@AndrasDeak: wrt the pandas 1.0.x issues I found with groupby missing some groups, and multiple issues with categorical and the new native 'string' vs Python 'object', the good news is that conda had lied to me about having updated to 1.0.3, it was still stuck on the very buggy 1.0.0, but the bad news is when I did successfully update to 1.0.3, the issues are still there. So, caution/workarounds still needed on the new pandas 1.0.x stuff.
 
I give it high probability that if someone were to ping the user with a helpful response, communication would be intermittent and difficult (having also looked at the user's profile and chat activity). I don't want to subject well-meaning regulars of the room to this fate.
@smci OK. But what I meant was that if you have a specific piece of code that we should test to see if it's buggy, I can run it.
 
@AndrasDeak I don't necessarily agree, but eh... fair enough for me
 
I completely concur with Andras on this. They actively left the room like 30 seconds after dumping code with no context
 
@Aran-Fey thanks
 
I'll agree with whoever has the most biscuits? :p
 
9:57 PM
I didn't realize they left... was worried they got kicked
 
nah
 
Nope, they removed themselves :)
 
10:15 PM
@AndrasDeak Appreciated, but my general one-line take on pandas 1.0.x is 'string' and 'category' native dtypes are nice, but buggy as ****. expect they have bugs, and in your code fall back on Python 'object' dtype.
 
that's "fine", I have no pandas code
 
@smci Did you answer my question earlier (it's possible I missed it sorry)
May 21 at 22:16, by roganjosh
I have to say that I've not experienced an "unholy mess", and breaking groupby would be a big deal. What's going wrong?
It seems like you're still on the same theme as that issue but I don't know how to set up something we can objectively test
 
10:32 PM
Any solution for using df[column].mean(numeric_only = True)? Obviously, it's a series, so numeric_only isn't allowed...
I want to get the average of a column but some values are non-numeric and I want to skip those
 
pandas.Series.mean(numeric_only) is a thing so I'm not sure what's obvious
Ugh
 
numeric_onlybool, default None
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
(Last sentence)
 
Why is the documentation so borked??
Ok, so you want only numeric types
 
And we assume the string '1.2' is not numeric?
 
10:39 PM
floats represented as strings are numeric under the definition of the function, so yes

But I'm only dealing with 1,2,3,4,5,'Not Available' values
What's sad is Series.Sum also doesn't accept numeric_only
 
Well this was my MCVE so far:
import pandas as pd

df = pd.DataFrame({'a': ['a', 'b', 1, '1', 1.2, '1.2'],
                   'b': ['fill1', 'fill2', 'fill3', 'fill4', 'fill5', 'fill6']
                   })
So we want the last 4 rows?
 
First pass at solving it: df = df.loc[pd.to_numeric(df['a'], errors='coerce').notnull()]
Actually, I think that'll be my only pass at this time of night. I'm not seeing another angle of attack
 
I could also iterate through every row of the column and add the cell value to the count if it's numeric via a for loop, but not sure how slow that would be...it's an 11k row DataFrame.
 
Sure. Let me know the timeit results :P
(I actually don't know the performance of to_numeric in this case so it may surprise me. But it's your question and I've already had to make an MCVE for you)
 
11:08 PM
It's giving me a strange 'df is not defined' error but I did
timeit.timeit("df.loc[pd.to_numeric(df['HHCAHPS Survey Summary Star Rating'], errors='coerce').notnull()]")
I initialized df
 
My own question: I have reservations about %timeit [i for i in l if i[0] == 5] where l is a numpy array when benchmarking, which is in a recent answer. I seem to remember an article about how numpy ints are exchanged with python ints but it was years ago. It works seamlessly in that line, but is broken with something external from the iterpreter, e.g. DB storage:
import sqlite3
import numpy as np

conn = sqlite3.connect(':memory:')
c = conn.cursor()

c.execute("CREATE TABLE test(id INTEGER PRIMARY KEY, testing INTEGER)")
conn.commit()

a = np.array([10000])[0]

c.execute("insert into test (testing) values (?)", (a,))
conn.commit()
print(c.execute("select * from test").fetchall())
conn.close()
Does anyone know the resource I'm trying to find? How is the numpy int type flipped so easily to a Python int?
 
Which part do you have concerns about? The i[0] == 5 check? Or the whole list comp?
 
Exactly that check. And its reverse with %timeit l[l[:,0] == 5] where we can compare against the integer literal
 
And what is the nature of your reservations?
 
There's some quick interchangeability going on
 
11:15 PM
Ah, I see why it's undefined; it has to be defined within the string
 
@JossieCalderon or pass a globals keyword
 
@AndrasDeak That I'm not sure whether we can benchmark the second code step against a list comp on a numpy array vs. an actual list
 
@roganjosh second code step?
Sorry, I have no idea what you're talking about :)
 
@AndrasDeak I'm being unclear, sorry. This is the benchmark. They're list-comping on the first time, so there is some conversion from a numpy int to a python int, inside the list comp. And the second test can use a native numpy int
 
I mean I don't even understand the question
@roganjosh well, yes. Looping over a numpy array and building a list is much slower than using array indexing. And the timing proves that.
 
11:19 PM
>>> timeit.timeit("pd.to_numeric(df['HHCAHPS Survey Summary Star Rating'], errors='coerce').notnull()", globals = globals(), number=100)
    0.5740766999999991
    >>> timeit.timeit("pd.to_numeric(df['HHCAHPS Survey Summary Star Rating'], errors='coerce').notnull()", globals = globals(), number=1000)
    5.562109799999998
    >>>
 
@JossieCalderon code plus reply will never work
 
So roganjosh, Every loop costs ~0.0057 seconds
 
@AndrasDeak I need to draft my question out again, I think. Apologies. I was trying to be succinct in something that I knew was going to need a few points :(
 
@roganjosh ah, so you're saying that [i for i in l if i[0] == 5] is slower for an array l than it would be for a list l
 
@AndrasDeak Yes, exactly that, and potentially in a way I don't know how it scales
 
11:23 PM
You can try pre-defining an np.int64(5) to compare against. Should remove most of the ambiguity. Looping a list vs an array will still be different of course, so what you're looking for in a fair comparison is [i for i in l.tolist() if i[0] == 5] or even better, precomputing the list version
 
It's clear that there is some implementation that can implicitly convert between the two int types (the python int and all the numpy ones) but does it work efficiently in both directions?
 
implicit conversion doesn't imply free comparison
 
Sure, and that's my reservation :)
 
and unlike doubles they can't really be bit-equivalent either, since python ints are not fixed-size
So yeah, I get your reservations, and the answerer could do better. The conclusion will not be affected by a more pedantic comparison, I'm sure.
(always worth checking, though)
n.b.:
>>> issubclass(np.float64, float)
True

>>> issubclass(np.int64, int)
False
 
This was mostly clarification. My original question was that I think there is an article somewhere that gives a high-level overview of how Python does this juggling trick between the types. I just can't find a trace of it. I guess it doesn't invoke any memories for you?
The implementation must be so low-level, I can't think of where to look exactly in numpy
 
11:27 PM
Doesn't ring a bell
 
@JossieCalderon Ok, so O(N). Not unexpected. I was suggesting that you benchmark against:
41 mins ago, by Jossie Calderon
I could also iterate through every row of the column and add the cell value to the count if it's numeric via a for loop, but not sure how slow that would be...it's an 11k row DataFrame.
0.0057 seconds for 11K rows seems pretty decent to me; I'd be surprised if a for loop over the DF would beat that
 

« first day (3508 days earlier)      last day (1439 days later) »