|
LochNessMonster posted:Thanks, that sounds like exactly what I am looking for. It's just math. Fluent Python will teach you about the python structures you use to implement the math...
|
# ? Aug 2, 2018 19:38 |
|
|
# ? Jun 3, 2024 22:09 |
|
baka kaba posted:Or if you just want to check it's close to all the values I really should look into generators at some point. I never use them. e: I have n lists of bools and I want an nth + 1 list to be built where it's True if the same elements for the other lists are all True and false otherwise. code:
Boris Galerkin fucked around with this message at 08:21 on Aug 3, 2018 |
# ? Aug 3, 2018 06:23 |
|
Python code:
I'm not exactly sure what is being specified though. I think you just want to and the two lists itemwise because bool([ False, False, False ]) is True. Ofc you can just any() the result if that is the goal. E: actually am I wrong about this? I think op.and does bitwise and? Are there not boolean operations in operator? When I do dir(op) in 3.7 it doesn't even list it ... This works though! Just a different name... which is why I suppose operator has no boolean and. I feel kinda silly for mentioning any but missing this ... Python code:
dougdrums fucked around with this message at 09:59 on Aug 3, 2018 |
# ? Aug 3, 2018 09:40 |
|
Boris Galerkin posted:I don’t know that book but the abs(a-b) < tol part to find a distance in both answers is just math. You learned it when you learned about number lines Apparently my math completely sucks. I’d expect this to check if a-b is smaller than 10. That’s not checking both ways right? I’d have to come uo with something like: abs(a-b) < tol or abs(b-a) < tol right? I didn’t know about generator expressions and they seem a lot more efficient than looping through lists all the time. baka kaba posted:Or if you just want to check it's close to all the values I am looking if just 1 value is close so this helped me find out about any(). Thanks. LochNessMonster fucked around with this message at 10:22 on Aug 3, 2018 |
# ? Aug 3, 2018 10:19 |
|
dougdrums posted:I think you just want to and the two lists itemwise because bool([ False, False, False ]) is True. Nah I wanted the list in my example comment (d = [False, False, True]). Python code:
Python code:
|
# ? Aug 3, 2018 10:21 |
|
LochNessMonster posted:Apparently my math completely sucks. I’d expect this to check if a-b is smaller than 10. That’s not checking both ways right? No, without the absolute value you'd need a-b < tol or b-a < tol, but the absolute value removes any negative sign so you only need to do the one comparison.
|
# ? Aug 3, 2018 10:23 |
|
LochNessMonster posted:Apparently my math completely sucks. I’d expect this to check if a-b is smaller than 10. That’s not checking both ways right? It's checking both directions because you take the absolute value of the result. If a = 10 and b = 15, then a - b = -5 b - a = 5 but abs(a - b) = 5 = abs(b - a) and 5 is the distance between the two numbers.
|
# ? Aug 3, 2018 10:24 |
|
It's generally called absolute difference, for the sake of searching. Just didn't see it mentioned.quote:Nah I wanted the list in my example comment (d = [False, False, True]). Python code:
I've been wondering if it is generally considered "more proper" to do this or the comprehension syntax. Comprehensions are cool and good but I'm really annoyed when I have to come up with a name every time. dougdrums fucked around with this message at 11:50 on Aug 3, 2018 |
# ? Aug 3, 2018 11:32 |
|
I've finished writing some code and am struggling to get to import. I'm using PyCharm if it matters. The project structure looks like https://imgur.com/5M75kfR I told it to create a setup.py, the contents of which is Python code:
I make a new project, use the command line to pip install it and in the venv it shows it in site-packages (a banking_scrape folder and banking_scrape-0.13.dist-info folder). However, if I do import banking_scrape it succeeds, but nothing I import seems usable. code:
My 2 __init__.py files are empty, but that seems to be normal? I'm so confused.
|
# ? Aug 3, 2018 13:08 |
|
I think that when you import banking_scrape it will execute the __init__.py file and since your __init__.py is blank nothing gets imported. You probably need to add in your __init__.py file e.g., from .core import * and so on. You also don't need to add banking_scrape.banks as a separate package. In the __init__.py file for it you can do the same from .virgin import *. In the top level __init__.py you can then just do from .banks import *. e: If there are name clashes in those bank files then you could just do code:
code:
Boris Galerkin fucked around with this message at 13:37 on Aug 3, 2018 |
# ? Aug 3, 2018 13:24 |
|
Boris Galerkin posted:
If I put from .banks import * in __init__.py it throws an error. code:
code:
edit - If I change __init__.py to Python code:
Python code:
code:
But that feels very much like not what I'm supposed to do. Sad Panda fucked around with this message at 14:48 on Aug 3, 2018 |
# ? Aug 3, 2018 14:26 |
|
Boris Galerkin posted:It's checking both directions because you take the absolute value of the result. drat this is getting pretty embarasssing... I guess I need to start spending some time on codewars/hackerrank.
|
# ? Aug 4, 2018 09:19 |
|
LochNessMonster posted:drat this is getting pretty embarasssing... Speaking of those type of sites, which do people like best for Python? Preferably with useful exercises for scientific/numerical programming?
|
# ? Aug 4, 2018 14:36 |
|
pmchem posted:Speaking of those type of sites, which do people like best for Python? Preferably with useful exercises for scientific/numerical programming? I probably hear project euler mentioned the most, and since its math-focused is probably the most appropriate for the discussion at hand. Not sure how similar you want to call it to hackerrank or the like... LochNessMonster posted:drat this is getting pretty embarasssing... My math is very weak so I feel your pain! I've been out of school for close to two decades with very minimal usage of any maths since then.
|
# ? Aug 4, 2018 15:32 |
|
Thermopyle posted:My math is very weak so I feel your pain! I've been out of school for close to two decades with very minimal usage of any maths since then.
|
# ? Aug 4, 2018 16:11 |
|
Fine, I'll do it! Though, I might find a precalc course to do first...
|
# ? Aug 4, 2018 16:27 |
|
I’m not an english native. Math is difficult enough in my primary language. Doing it in english makes it even harder. I should give it a shot though...
|
# ? Aug 4, 2018 16:53 |
|
Sad Panda posted:If I put from .banks import * in __init__.py it throws an error. In your overview.py file, you need to change your local imports from other modules from code:
code:
code:
quote:If I change __init__.py to This does absolutely nothing by the way. I'm actually surprised this doesn't cause a circular dependency issue. Because it's saying "from the banking package, execute __init__.py, which then says "from the banking package, execute __init__.py, which then says, "from the ...""". You need to actually tell __init__.py what to import. Also your __all__ variable doesn't do what you think it does. __all__ is use for when you want to limit what gets imported when you do import *. For example if I had a file code:
|
# ? Aug 5, 2018 13:25 |
|
Thermopyle posted:Fine, I'll do it! Whenever I tutor calculus (or any other higher level math) the thing that 99% of my students have trouble with isn't precalc or calculus or the harder stuff in differential equations. They all have issues that stem from ... algebra. People have no idea how to simplify/reduce equations or how fractions work. I would suggest brushing up with an algebra course .
|
# ? Aug 5, 2018 13:28 |
|
It's funny you said that because as I was looking over prerequisites for various courses I decided an algebra refresher was exactly what I should start out with! Thanks for confirming I wasn't a big dummy for thinking that.
|
# ? Aug 5, 2018 15:34 |
|
Hi thread. I am new to Python and trying to construct a tree for homework. I did a short test and have a problem: code:
N N's second child X's child I would expect that node y would have no children, so I'm confused. What am I doing wrong?
|
# ? Aug 6, 2018 01:53 |
|
TerraGoetia posted:Hi thread. Try defining your class like this: Python code:
Using the constructor like in the code snippet here instantiates Node.children as an instance attribute, so each instance of Node gets its own list independent from other instances QuarkJets fucked around with this message at 02:26 on Aug 6, 2018 |
# ? Aug 6, 2018 02:23 |
|
That makes sense! Thank you!
|
# ? Aug 6, 2018 02:27 |
|
Thermopyle posted:Thanks for confirming I wasn't a big dummy for thinking that. Don't feel silly because if you think about it when was the last time you or most people (in the US) studied/learned algebra? I would wager it was in high school and from whatever teacher they could find that was vaguely "good at math." And after that one algebra class people move on and never revisit it again, and by the time you're taking calculus every professor just assumes that you know algebra because it's "basic stuff" despite the fact that you only learned what you needed to learn to pass whatever state mandated fill in the bubble with a #2 pencil exam there was at the time. Boris Galerkin fucked around with this message at 07:01 on Aug 6, 2018 |
# ? Aug 6, 2018 06:59 |
|
If I'm writing some scripts to do ETL, should I be concerned with building classes and stuff? I'm not really a programmer so some of the OO concepts are foreign to me.
|
# ? Aug 6, 2018 14:20 |
Mark Larson posted:If I'm writing some scripts to do ETL, should I be concerned with building classes and stuff? I'm not really a programmer so some of the OO concepts are foreign to me. If you just do transport, probably not. Otherwise - probably yes.
|
|
# ? Aug 6, 2018 14:31 |
|
Boris Galerkin posted:lots of help Thank you for that. I ended up getting it fixed (https://bitbucket.org/dluther23/bankscrape/src/master/). I tried forever with the .core thing, but couldn't get it working properly. Python code:
|
# ? Aug 6, 2018 22:51 |
|
What's the best way to take some JSON from an API response, parse it and load it to a Postgres/Redshift database? I'm able to get the API response, and use psycopg2 to load a table with JSON in it, so the only thing now is to unpack it and load it. The load is actually a dictionary of dictionaries, so I would need to do some additional unpacking to load three tables from one API call/response. Is pandas.io.json_normalize the best way to handle this? I thought I could get some answers from Stack overflow but it's kind of all over the place.
|
# ? Aug 8, 2018 10:57 |
Mark Larson posted:What's the best way to take some JSON from an API response, parse it and load it to a Postgres/Redshift database? I'm able to get the API response, and use psycopg2 to load a table with JSON in it, so the only thing now is to unpack it and load it. If you have very well formed, consistently serves, JSON, then yes, you could maybe try pandas normalisation. Otherwise I’d just write a custom thing for that specific JSON.
|
|
# ? Aug 8, 2018 11:34 |
|
I'd like to plot the Recamán sequence as they do here: https://www.youtube.com/watch?v=FGC5TdIiT9U Not only would I like to create the plot, I'd like to animate it so you see the line growing from zero to whatever. I've never done anything with computer graphics of any type so I have no idea where to start. My outside view is that the stuff you normally hear about when doing graphs with python like matplotlib are more for static graphics. Maybe I should use PyGame? I don't really know what I need here.
|
# ? Aug 8, 2018 17:35 |
|
Here's an API designed to make animating in MPL easier. Can you accomplish what you want using snapshots of MPL, or do you need something more custom?
|
# ? Aug 8, 2018 17:43 |
|
Just to give you an idea where my experience level is when it comes to putting graphics on a computer screen via a programming language: I don't even know wtf MPL is.
|
# ? Aug 8, 2018 18:28 |
Thermopyle posted:Just to give you an idea where my experience level is when it comes to putting graphics on a computer screen via a programming language: Matplotlib, hands down the most confusingly complex API I've ever worked with. You can get anything plotted with it in Python, sometimes just at a cost.
|
|
# ? Aug 8, 2018 18:31 |
|
Oh, well fuckin duh, Thermopyle.
|
# ? Aug 8, 2018 18:31 |
|
cinci zoo sniper posted:Matplotlib, hands down the most confusingly complex API I've ever worked with. You can get anything plotted with it in Python, sometimes just at a cost. In the major release a few months back, they changed the default display settings to be more sensible, at least. If you want something truly custom, you could try this SDL binding. SDL is a C-based lib commonly used to draw arbitrary things on the screen. Probably overkill/too low-level for your use here. Qt has a decent drawing lib too. Dominoes fucked around with this message at 18:58 on Aug 8, 2018 |
# ? Aug 8, 2018 18:39 |
|
Matplotlib would get the job done, but I would personally recommend bokeh, possibly with holoviews. With any of these you can achieve the animation natively, use a slider, or export images to be stitched into a video with another library or external program. In any case, start by just making a static plot and go from there.
|
# ? Aug 8, 2018 18:55 |
|
Alternatively it seems like a very turtle thing:
|
# ? Aug 9, 2018 13:50 |
|
I'm trying to make a project of mine a little more modular by having a dependency injector manage selecting what version of something to use based on runtime constraints. The source is constrained by subdirectories. Let's see I am trying to implement Butt: root_name/api/butt_api.py: Contains abstract base classes root_name/default/butt.py: Most common fallback of Butt root_name/windows/butt.py: A Windows-specific version of Butt The method of choosing which one to use has been solved a long time ago; I have no problems there. My issue is that I'd like to be able to install the Butt feature independent of other modules in this tree structure, while having it coexist with everything else. So I'd like to package a butt.whl that installs into root_name under my Python site-packages. If I come along and install foo.whl then I want that to also go into root_name in the right places. Ditto for uninstalling. I'd prefer if root_name could be uninstalled if the last module that uses it is removed, but it's probably more practical to have the parent project that consumes this tree and does the injection to initially set up that whole structure, if possible. Is that a thing I can do from one Python wheel?
|
# ? Aug 11, 2018 23:54 |
|
I've got a producers/consumer setup that adds and removes data between a set of queues. One step of the pipeline is network IO bound, where it loads data from one queue, fetches related data from the internet and puts the result in another queue to be consumed by a pool of CPU-bound processes. Ran some benchmarks and using asyncio is much faster than using threads in this context. Is there a way to share queues between an async context and a synchronous one without blocking on the async side?
|
# ? Aug 12, 2018 20:07 |
|
|
# ? Jun 3, 2024 22:09 |
|
A bit late but Mark Larson posted:If I'm writing some scripts to do ETL, should I be concerned with building classes and stuff? I'm not really a programmer so some of the OO concepts are foreign to me. This strongly depends on what kind of ETL we are talking about, how complex your processes are, and if there are dependencies between various steps. For slightly more complex requirements with dependencies, required job control, and cascades, have a look at Spotify's Luigi. It's particularly useful for interdependent steps and I use it at work for a number of relatively light-weight ETL processes. It uses a pretty neat set of Classes to encapsulate inputs, outputs and dependencies between tasks. Mark Larson posted:What's the best way to take some JSON from an API response, parse it and load it to a Postgres/Redshift database? I'm able to get the API response, and use psycopg2 to load a table with JSON in it, so the only thing now is to unpack it and load it. Have a look if pandas is good enough. Depending on how deep the nesting is, I usually tend to use nested dict comprehensions to flatten dictionaries when I want more control and/or need to ensure data quality in a more granular way. I find this particularly useful for large data, since it gives me more explicit control over chunking, and I can use iterators for lazy evaluation (pandas is not great when trying to parse a 90GB JSON file, for example). Hollow Talk fucked around with this message at 23:07 on Aug 12, 2018 |
# ? Aug 12, 2018 23:00 |