|
I often do something like this:code:
Specifying the parameter to some arbitrary value before the while loop feels inelegant. Is there a better way for doing this? A more fleshed-out example, maybe I want to randomly draw an even integer between 140 and 75858 whose third-to-last digit is a 4 or a 7 for whatever reason: code:
I guess this is a very minor thing, but it's a pattern I use all the time and it feels weird.
|
# ¿ Mar 15, 2017 12:42 |
|
|
# ¿ May 2, 2024 12:51 |
|
HardDiskD posted:I try to start with None or a boolean value if I don't have a default value that makes sense. But sometimes these 'natural defaults' match the condition. E.g., what if False matches my criterion of being (not var % 2 and var < 1000)?
|
# ¿ Mar 15, 2017 13:26 |
|
I like the generator one! Thanks guys.
|
# ¿ Mar 15, 2017 15:41 |
|
SurgicalOntologist posted:I don't fully understand the algorithm but the first step is to try to do this with vectors operation. This might not work as written but may only need small tweaks. At least it should illustrate the idea of vectorizing the operation.
|
# ¿ Apr 11, 2017 11:55 |
|
QuarkJets posted:[i for i in range(1, 100, 1)]
|
# ¿ Apr 12, 2017 10:20 |
|
For real though, how did you oldsters ever live with Python 2 and its leaking list comps?
|
# ¿ Apr 12, 2017 14:14 |
|
HardDiskD posted:You mean the leaking variable that is used on building the comps In other news, I may be literally the worst coder ITT, but I got really good teacher evaluations on my recent Python class and we'll try and apply for funding for a bigger project for teaching Python to students, and for using Python to teach science to students
|
# ¿ Apr 12, 2017 14:27 |
|
code:
|
# ¿ Apr 13, 2017 14:22 |
|
Different question: does Continuum make money? What are the chances "conda install all_the_software_i_need" won't work in 2018 because Travis Oliphant has to choose between making it slightly easier for me to set up numpy or feeding his kids?
|
# ¿ Apr 18, 2017 11:53 |
|
I also have a Pandas question. I have a multi-indexed Dataframe. I want to subset the DF based on the value of column A, and then look up stuff in the original DF based on values of one of the index columns and one of the regular columns in the subset, but in pairs. E.g., the subset is code:
code:
code:
huhu posted:2018? I don't think anything is guaranteed 3 months from now. SurgicalOntologist posted:The nice thing about a heavily used open source project is that it cannot really go away. If Continuum disappears the code will still exist and there will be enough volunteers to maintain it. Now a lot of the times, this will work out fine, somehow. But I'm sure if Continuum went under, things would change, and probably not for the better.
|
# ¿ Apr 18, 2017 16:22 |
|
Why is there no natural sort in standardlib!?!!!
|
# ¿ Apr 24, 2017 19:33 |
|
dougdrums posted:
Python code:
|
# ¿ Apr 27, 2017 06:39 |
|
Eela6 posted:Mods?
|
# ¿ Apr 27, 2017 09:10 |
|
My Rhythmic Crotch posted:I am looking for a python module to help me do some design/sim type of work. I want to build an object as a 3d array of points, and be able to interact with the object (zoom, rotate, etc). A 3D surface plot in matplotlib is almost exactly what I want, except when viewing the plot it's really clunky and hard to interact with. So basically something just like that, except less frustrating. There doesn't seem to be much out there for this. Any suggestions welcomed.
|
# ¿ May 26, 2017 12:05 |
|
pangstrom posted:Probably sounds like faux outrage but I'm really just curious: is starting bullet lists for human consumption with element zero something programmers routinely do?
|
# ¿ Jun 1, 2017 21:19 |
|
Now tell them about ... the stars.
|
# ¿ Jun 7, 2017 19:33 |
|
Baby Babbeh posted:What's the best way to go through a pandas dataframe and convert all of the values to a different value if they meet a set criteria? I've got a data frame representing grayscale images, where each cell is a value between 0 and 255, and I'd like to just convert this to black and white by changing anything that's not zero into a 1 prior to doing some analysis on it. Is this something I should use .apply for? df[df != 0] = 1
|
# ¿ Jun 8, 2017 20:40 |
|
Baby Babbeh posted:That... makes sense. I was overcomplicating this. It returns another df rather than changing it in place, right? indices = df != 0 df[indices] = 1
|
# ¿ Jun 9, 2017 00:27 |
|
Interesting, I literally never use .where. Have to look into that. Also ing the py3redirect
|
# ¿ Jun 9, 2017 18:59 |
|
Malcolm XML posted:
|
# ¿ Jun 11, 2017 14:13 |
|
Malcolm XML posted:any programmer that's using floats for numerical work needs to know when and how they work so when they gently caress up they aren't surprised. math.fsum is in the standard library for a reason pmchem posted:anyone involved with scientific software should be aware of floats I would think the entire neural network community largely ignores floating point issues, what with them running near-exclusively on single precision. Malcolm XML posted:Actually this is the worst possible takeaway because Numerical analysis is a) hard and b) for even most practical purposes requires an understanding of when it'll fail on you. Catastrophic cancellation and loss of precision can lead to cases where your component will fail and fail hard. Unless you don't want to engineer robustly, sure you can ignore it. I have run into many cases where poor or no understanding of float approximations have lead to pernicious bugs in production systems costing lots of money
|
# ¿ Jun 11, 2017 23:48 |
|
Malcolm XML posted:it's not as fun I don't mean this to disparage you or as a counterargument to your position - which it is not - but as advice from someone who should've been given that lesson much earlier themselves, too. shrike82 posted:yup, google's TPUs use quantization to improve inference performance so you can't say that ML practitioners can ignore FP issues (I'm obviously not saying these people are ignorant of the issues, just that the issues are largely irrelevant, and being ignored.)
|
# ¿ Jun 12, 2017 10:54 |
|
shrike82 posted:An ML practitioner or academic could decide to ignore precision based on their needs, but I'd find it hard to argue that one can make an informed decision without understanding the basics of floating point arithmetic. (For applied guys like me, it might be different, and it's possible people are getting hosed over here from time to time.)
|
# ¿ Jun 12, 2017 12:19 |
|
I think I need async/await ..? But I have never used either, nor understood the descriptions. I am training a neural network on synthetic data, and I'm alternating data generation and training. So it looks like this: code:
code:
Edit: both functions fully occupy 1 core. I think that means await is not enough? Maybe I should just abuse joblib heavily, that I could do. Double Edit: joblib uses pickling and the model is compiled and sent to the GPU, so I think joblib wouldn't work. Cingulate fucked around with this message at 14:35 on Jun 15, 2017 |
# ¿ Jun 15, 2017 14:32 |
|
Thanks everyone. I think step 1 should be to make my generate_data less horribly ineffective, it's a big nested loop. Bummer - I thought this'd force me to learn something new
|
# ¿ Jun 15, 2017 16:48 |
|
I know joblib and multiprocessing's pool - I use them a lot actually, because most of my problems are trivially parallelizable. This one, I fear, is not: the training happens in Theano (I think I hosed something up with my Tensorflow installation?), so it compiles CUDA code for the GPU and then it sits there. So the training always needs to happen in the main thread/kernel/session. But yes, if I can send the data generation to a secondary process, that would save me some time. So this can be done with the multiprocessing module, did I get that right?.. (Having multiple X sit in memory probably isn't viable cause they're pretty big - tens of GB - , but I guess I can make them smaller and find a few GB somewhere and it should work.)
|
# ¿ Jun 15, 2017 22:12 |
|
shrike82 posted:Out of curiosity, what is the NN problem you're working with?
|
# ¿ Jun 16, 2017 21:05 |
|
I'm sure if you can organize it in matrix form/numpy/pandas, it's gonna run in a fraction of the time. Essentially, you want to vectorize it: instead of having objects per dataset, you just have one matrix, and apply each of these operations simultaneously to all of its rows. And to perhaps slightly increase readability for baka's code: code:
|
# ¿ Jun 17, 2017 17:38 |
|
Philip Rivers posted:Okay, so I have a set of points and a set of lines defined by two endpoints. Basically I'm working on an intersection algorithm and I need to figure out when a given point intersects one of the lines, but what makes it tricky for me is that the lines exert force on the endpoints and pull them together so the position of the endpoints are constantly updating. Here's what it looks like in action:
|
# ¿ Jun 20, 2017 19:48 |
|
Philip Rivers posted:Do you have any resources on this? I'm very out of my depth with a lot of this and I'm just fumbling in the dark. https://s3.amazonaws.com/assets.datacamp.com/blog_assets/Numpy_Python_Cheat_Sheet.pdf Generally, Numpy is your pythonic way of calling highly optimized packages for numerical computation. As Eela6 said, try to vectorize: not much looping, but operating on vectors and arrays as a whole.
|
# ¿ Jun 20, 2017 20:09 |
|
SirPablo posted:Damnit that does work. Thanks for pointing out my idiocy. Suppose I can take the output values and make a new Dataframe with them.
|
# ¿ Aug 2, 2017 17:25 |
|
If it's tabular data, just use pandas read_csv (and make plots in seaboard).
|
# ¿ Aug 14, 2017 16:08 |
|
Situations where I can see the hand-crafted option make sense: - you're analysing data and tweeting on an embedded system running python 2.6 on 128MB RAM - you want to Learn Python the Hard and Manly Way Situations where I'd prefer the Pandas option: - you want to get things done and learn the tools you're actually gonna use in real situations Anything I forgot? Jose, in case "seaboard" confused you, I apologise: install anaconda and go here.
|
# ¿ Aug 14, 2017 20:11 |
|
Eela6 posted:I don't feel that way. I don't particularly like pandas, and I prefer using the stdlib where possible. You have to consider the audience of your code, too. Jose is very new to python; the last thing he needs is a thousand different APIs to understand.
|
# ¿ Aug 14, 2017 20:24 |
|
Eela6 posted:I don't feel that way. I don't particularly like pandas, and I prefer using the stdlib where possible. You have to consider the audience of your code, too. Jose is very new to python; the last thing he needs is a thousand different APIs to understand. (You're probably using CSVs/pandas because 1. the party/platform you got the data from uses CSVs/stuff pandas can easily parse.) I don't think this is about "big guns". It's just so much more handy to use pandas and the standard scientific Python stack even for tiny data. It seems like 1/3rd of questions ITT are solved by SurgicalOntologist posting a pandas one-liner.
|
# ¿ Aug 14, 2017 22:05 |
|
Jose posted:Ok i'll check out pandas. Thanks everyone. I was using QtConsole launched through anaconda yesterday but would spyder be more suitable?
|
# ¿ Aug 15, 2017 09:23 |
|
Jose posted:Can anyone link a good guide for combining pandas and matplotlib? Basically how matplotlib usage differs if I'm using pandas data frames
|
# ¿ Aug 16, 2017 10:49 |
|
Slimchandi posted:That's my general approach; I'm sure I will find some dead ends along the way but that's how I will learn the most about it.
|
# ¿ Sep 4, 2017 20:45 |
|
A while ago, I complained about dict(this_will_become_a_str=var) syntax. Somebody told me I was silly because dict is highly convergent with regular kwargs. I have in the meantime understood your point, and it has essentially made me more comfortable using **kwargs well.
|
# ¿ Sep 25, 2017 11:39 |
|
|
# ¿ May 2, 2024 12:51 |
|
JVNO posted:I use PsychoPy to run Psychology experiments. Right now, I'm doing an experiment where participants view a word in multiple different fonts. Here's my problem: The fonts need to be markedly different between presentations, but the letters themselves should always appear in the same spot. So while common monospaced fonts are far too similar to one another, variable spaced fonts tend to result in a much smaller word width with smaller spacing between words. code:
|
# ¿ Sep 28, 2017 22:36 |