|
Nah, I'd have to reload all the data again and somehow specify which race it was. They were all 5ks though (although I know that the terrain could have a bit of an effect on the times). Thanks for introducing me to Pandas and Seaborn though. I'd begun to think that Python didn't have any great data analysis/visualization tools. Seaborn looks beautiful.
|
# ? Jul 22, 2014 05:04 |
|
|
# ? May 9, 2024 02:57 |
|
the posted:Write a code that checks to see if a supplied string is a palindrome or not. code:
EAT THE EGGS RICOLA posted:Project Euler is alright, so is checkio.
|
# ? Jul 22, 2014 05:09 |
|
Try this next: Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?
|
# ? Jul 22, 2014 05:21 |
|
the posted:Try this next: Bonus for solving in polynomial time?
|
# ? Jul 22, 2014 05:59 |
|
pmchem posted:Bonus for solving in polynomial time? I think you'd also get a Fields Medal for that.
|
# ? Jul 22, 2014 06:08 |
|
the posted:Interesting, I don't know what you did there, but interesting: I'm wondering about those 5 99 year olds; they make up a third of the 80-100 bracket. Could they be incorrectly recorded? (I'm actually kind of guessing that the ages are two digits maximum, or perhaps more likely, 99 indicates unknown age) ohgodwhat fucked around with this message at 13:45 on Jul 22, 2014 |
# ? Jul 22, 2014 13:42 |
|
rock2much posted:I started doing some more of the Euler ones when I got home so I got the number version of this done. Will try strings tomorrow if work is slow. You're forgetting to check for 999! Remember how range (and slicing) works in python, it's doing 100 <= x < 999. Try breaking your code into functions, like for example there's clearly some kind of function "is_palindromic" trying to come out of this. I don't know, I think it's good style and makes it easier to reason about. code:
Probably the biggest thing that will help speed up the code is to notice that multiplication is commutative (a*b == b*a) so you don't really need to loop over so many pairs like that, it's a waste of time to check for b*a if you already checked a*b. Also you can reduce the number of times you compute a*b by holding the value in a variable.
|
# ? Jul 22, 2014 14:00 |
|
Symbolic Butt posted:You're forgetting to check for 999! Remember how range (and slicing) works in python, it's doing 100 <= x < 999. You're right about the 100 <= x < 999 thing, forgot all about it. I can't wrap my mind around how to make the a*b == b*a into less computations. The logic is sound, I just don't know the code to make it less than it is. Also thanks!
|
# ? Jul 22, 2014 15:14 |
|
Sweet graphs, the.
|
# ? Jul 22, 2014 15:21 |
|
rock2much posted:You're right about the 100 <= x < 999 thing, forgot all about it. You only need to consider cases where b >= a. This is easily achieved by changing where the range for b starts. You could actually loop over the product of a*b instead of b: code:
|
# ? Jul 22, 2014 16:16 |
|
BabyFur Denny posted:You only need to consider cases where b >= a. This is easily achieved by changing where the range for b starts. In this example, a is 100 start at 100*100, end at 100*1000, count-up/step by 100 first output is 10000 (100*100) second is 40000 (200*200), etc etc When a is 101: 101*101 then 202*202, etc 102 is 102*102 then 204*204, etc If I'm reading this right, and I'm probably not, does it ever get to do 101*102 and I guess the other numbers it's missing? Does it need to?
|
# ? Jul 22, 2014 19:20 |
|
101*102 does get checked. If a is 101, then b starts at 101*101, but on the next iteration b becomes 101*101+101, which is equivalent to 101*102. And then b becomes 101*101+101+101, which is equivalent to 101*103, etc. For completeness, BabyFur Denny alludes to another way to check every combination of numbers between 99 and 999 only once, which would be something this: Python code:
Second loop, you get to check 101*101, 101*102, 101*103, etc Eventually a is 998, at which point b only becomes 998 and then 999 (rather than looping through all values between 99 and 999 again) The two methods are equivalent. What BabyFur Denny posted is a little more compact (by one line), but this one's a little easier to read QuarkJets fucked around with this message at 19:49 on Jul 22, 2014 |
# ? Jul 22, 2014 19:41 |
|
I've decided to solve your problem with a horrific one-liner. Never code like this:Python code:
|
# ? Jul 22, 2014 19:58 |
|
QuarkJets posted:I've decided to solve your problem with a horrific one-liner. Never code like this: Thanks for the explanation AND making my head explode with the one liner . Because I'm a poo brain I saw the (a*a, a*100, a) and thought the a*a portion increased by a each time, so it's like a*a, then 2a*2a, then 3a*3a instead of what it actually does, just increase the total, b, by a .
|
# ? Jul 22, 2014 20:10 |
|
You can also use itertools.combinations_with_replacement itertools owns
|
# ? Jul 22, 2014 20:29 |
|
Is there a canonical way to get a column vector in numpy? The obvious a.T doesn't work on a normal vector. If I want to get a 1-5 multiplication table in Matlab I can do:code:
code:
There's obviously a bunch of ways to do this: code:
|
# ? Jul 22, 2014 22:39 |
|
Still a bit crude but another way isPython code:
|
# ? Jul 22, 2014 22:46 |
|
KernelSlanders posted:Is there a canonical way to get a column vector in numpy? The obvious a.T doesn't work on a normal vector. If I want to get a 1-5 multiplication table in Matlab I can do: You can use the outer product, that's what I use when I need something like that: np.outer(a, a) Maybe someone better than me can answer you why working with column vectors aren't that great.
|
# ? Jul 22, 2014 22:54 |
|
I have the following function:Python code:
Any clarification as to why this works would be appreciated.
|
# ? Jul 23, 2014 05:06 |
|
Jose Cuervo posted:The parameter filter is optional, but if provided will be a string (e.g., 'agent'). I am not sure why (as far as I can tell) the if statement works, i.e., when filter is not specified the code following the if statement is not executed, but if filter is set to something other than None then the code following the if statement is executed. If you don't specify a filter then it gets set to None. If the filter is not None then the code inside the if is run.
|
# ? Jul 23, 2014 05:13 |
|
Nippashish posted:If you don't specify a filter then it gets set to None. If the filter is not None then the code inside the if is run. I understand that part. What is unclear to my is why "None is not None" evaluates to False, but something like "'agent' is not None" evaluates to True.
|
# ? Jul 23, 2014 05:21 |
|
Jose Cuervo posted:I understand that part. What is unclear to my is why "None is not None" evaluates to False, but something like "'agent' is not None" evaluates to True. Because None is not None is a false statement. That's why it evaluates to false. None is None. Basically you asked Python to evaluate this: code:
|
# ? Jul 23, 2014 05:26 |
|
"is not" means "are the two things not the same thing"? None and None are the same thing. 'agent' and None are not the same thing.
|
# ? Jul 23, 2014 05:33 |
|
Jose Cuervo posted:I understand that part. What is unclear to my is why "None is not None" evaluates to False, but something like "'agent' is not None" evaluates to True. There is only one None in python. That's why None is None. On the other hand, is is sometimes pretty weird code:
|
# ? Jul 23, 2014 05:35 |
|
rock2much posted:I started doing some more of the Euler ones when I got home so I got the number version of this done. Will try strings tomorrow if work is slow. Python code:
|
# ? Jul 23, 2014 06:20 |
|
Nippashish posted:There is only one None in python. That's why None is None. On the other hand, is is sometimes pretty weird is checks the identity of the underlying object. So if you did... code:
code:
Lyon fucked around with this message at 07:08 on Jul 23, 2014 |
# ? Jul 23, 2014 07:01 |
|
Lyon posted:So if you want to know if two variables point to the same object you use is, if you want to know if two values are equal you use ==. I was just trying to point out that when two things are actually the same object is not always intuitively obvious.
|
# ? Jul 23, 2014 07:05 |
|
Oh whoops, misunderstood! Disregard this post.
|
# ? Jul 23, 2014 07:12 |
|
It depends on what the meaning of 'is' is.
|
# ? Jul 23, 2014 07:19 |
|
Nippashish posted:There is only one None in python. That's why None is None. On the other hand, is is sometimes pretty weird The reason for this is because ints under 256 (and also 0 to -5 or something I think) are cache'd so it uses the same object to avoid creating lots of new objects with basic calculations people tend to do. None is also a cache'd object so all None would be the same as any other None. I'm guessing "123456789 is 123456789" is True because it must be an optimisation to only create a single int object if they're both in the same statement.
|
# ? Jul 23, 2014 08:32 |
|
ShadowHawk posted:As an aside to the above changes, there's a quick code smell here: you're calculating a*b 3 times, and I don't think Python is smart enough to cache it. lol if you believe multiplies are expensive.
|
# ? Jul 23, 2014 12:18 |
|
Suspicious Dish posted:lol if you believe multiplies are expensive.
|
# ? Jul 23, 2014 14:31 |
|
Style question:Python code:
Python code:
|
# ? Jul 23, 2014 14:43 |
|
Neither a fedora nor bowler hat are going to be stylish. Try a baseball cap or a pork pie hat.
|
# ? Jul 23, 2014 15:12 |
|
ShadowHawk posted:Style question: No parentheses 4 lyfe.
|
# ? Jul 23, 2014 15:31 |
|
Thermopyle posted:No parentheses 4 lyfe. Agree w/ this dude.
|
# ? Jul 23, 2014 16:06 |
|
Stupid question, I know, but I'm not sure why this isn't working:code:
code:
code:
|
# ? Jul 23, 2014 16:22 |
|
query_opps[1]['OpportunityContactRoles'] is a list with a dictionary in it so do:code:
|
# ? Jul 23, 2014 16:26 |
|
I have a list of 176,876 Ids (strings), and I am trying to find an easy way to group them by occurrences (so I can plot it later). Is this something that Pandas can do? I've loaded them into a DataFrame. Running something like df.pandas.groupby('ID').group() seems to sort of do what I want (printing out every string and the list locations where it occurs), but I'm really looking for something like: code:
Second edit: Importing the list into a dataframe, I ended up having to write the list to a CSV file and then load it into the dataframe. I couldn't find a way to load a list into a dataframe directly even after reading the Pandas documentation. Did I miss something? the fucked around with this message at 19:44 on Jul 23, 2014 |
# ? Jul 23, 2014 19:41 |
|
|
# ? May 9, 2024 02:57 |
|
the posted:I have a list of 176,876 Ids (strings), and I am trying to find an easy way to group them by occurrences (so I can plot it later). Is this something that Pandas can do? You might also want to check out value_counts. For example if your column was named 'ID' then you would use the call: Python code:
Jose Cuervo fucked around with this message at 20:35 on Jul 23, 2014 |
# ? Jul 23, 2014 20:32 |