Skip to main content

New answers tagged

1 vote

Resource reservation system

Unless you have a really good reason (you don't seem to), start_date and start_time should never be represented independently, ...
Reinderien's user avatar
  • 65.3k
2 votes

Minimization problem solving and its step limits

Determinism If your various calls to randint are for some kind of Monte Carlo process, then fine; but it's crucially important that you have controllable state. You ...
Reinderien's user avatar
  • 65.3k
0 votes

Snake game using python and tkinter

Overview The code layout is good, and you used meaningful names for classes, functions and variables. UX It is not obvious what the user should do when the GUI opens up. You should display some simple ...
toolic's user avatar
  • 6,082
3 votes

Determine the hyper-parameters of an Approximate Bayesian computation

what can I do to improve the speed of my algorithm? You have an (impressive) seven-deep nested loop, where only one of the levels of the nested loop takes up to \$10^7\$ iterations. Taking a guess at ...
Reinderien's user avatar
  • 65.3k
2 votes

Python - How to efficiently bin multiple dependent variables to a common independent variable?

Don't use linspace, among other reasons because that doesn't return a useful dtype by default. Just use arange, and then you can ...
Reinderien's user avatar
  • 65.3k
2 votes

Connect 4 project for three players with Pygame graphics

UX Add a title to the GUI to show that it is the Connect 4 game. Also mention in the GUI that there are 3 players: red, yellow and green. In addition to the GUI, the code prints a lot of output to the ...
toolic's user avatar
  • 6,082
2 votes

A simple word embedder only using jax

As @J_H pointed out in a comment, there is no more information other than your code to base these improvements upon. Thus, take it with a grain of salt. Use Direct Embedding Lookups Right now, your <...
Linny's user avatar
  • 10.4k
4 votes

Calculate optimal game upgrades, v2

Performance Improvements Reduced Complexity for get_max_dollars Currently this tries all possible dollars from max dollars down to 0, this is ...
Linny's user avatar
  • 10.4k
4 votes
Accepted

Using python to estimate the range of unstructured data

My results are very sensitive to the bin size That's going to be difficult to escape. There are some automatic ways to estimate bin size; as an example for your input data and using ...
Reinderien's user avatar
  • 65.3k
2 votes
Accepted

Polynomial parsing using regular expressions in Python

problem name Names strongly influence how we think about a problem. I'm not happy with the one you chose. Consider your \$-3t^2 + x\$ example. Prefer to use ...
J_H's user avatar
  • 34.8k
3 votes

Median of two sorted arrays in Python

The previous answer addresses your main concern about complexity. This will address one of the now-deleted comments on the question regarding functionality. Portability The function that was posted ...
toolic's user avatar
  • 6,082
3 votes

Sampling distribution of the sample mean

I seek advice on how to improve the program's efficiency You use Numpy already; use it (a lot) more. as well as to improve the user interface For any significantly long input, I don't think it's ...
Reinderien's user avatar
  • 65.3k
2 votes

Calculation of independence test statistic

Here are some performance improvements (new code appears 3-4x faster on the sample data). Focusing on numpy. I think it's okay to sacrifice modularity for the sake of performance, although I'm not ...
Eman Yalpsid's user avatar
  • 1,519
2 votes

Iteratively Build a Summary Dataset in an Effective Way

I only know how to do so utilizing nested For loops Replace that with Pandas calls. Can I achieve this goal without consuming so much time? Other than loop, group and index issues, your output ...
Reinderien's user avatar
  • 65.3k
6 votes
Accepted

Median of two sorted arrays in Python

mentioned that \$O(\log \min(n,m))\$ would be really outside of what I can understand with my current knowledge. Nah! It's really about the sizes \$n, m\$, rather than about the algorithm. If one is ...
J_H's user avatar
  • 34.8k
3 votes

How to optimize code to take advantage of NumPy broadcasting when calculating pairwise correlation?

"Yes". Your OLD IMPLEMENTATION isn't that far off, but needs to be vectorised. For these purpose I suggest dropping down to Numpy for the inside of the ...
Reinderien's user avatar
  • 65.3k
2 votes

I have a pytorch module that takes in some parameters and predicts the difference between one of it inputs and the target

computing a discarded result Please don't write code like this: def greet(name): 42 name + " is cool." print(f"Hello {name}!") Yes, ...
J_H's user avatar
  • 34.8k
2 votes
Accepted

JiraWatcher - A script that helps track the progress of testing versions

module-level actions load_dotenv() jira = Jira( url=os.getenv('JIRA_URL'), username=os.getenv('JIRA_USERNAME'), password=os.getenv('JIRA_PASSWORD') ) ...
J_H's user avatar
  • 34.8k
2 votes

JiraWatcher - A script that helps track the progress of testing versions

Overview You did a good job with: Leveraging others code with the imports Using meaningful names for classes, functions and variables. Layout Move the functions ...
toolic's user avatar
  • 6,082
2 votes

Finding the Euclidean distance between the vectors of matrix a, and vector b

Don't use math in a Numpy context. You should vectorise your loop. You had figured this out in a now-deleted answer, where you also passed axis=1. However, in ...
Reinderien's user avatar
  • 65.3k
6 votes
Accepted

Phonebook (working with vCard file)

Documentation You should add a docstring at the top of the code to: Summarize its purpose Emphasize it relies on an environment variable State the format of the required input file with a reference ...
toolic's user avatar
  • 6,082
2 votes

Computing the angle between two vectors (vectorized) for small angles and with few copies

I want to do this with as few copies as possible This should not be a concern while your function is incorrect (your "sign error"). But also: should this - ...
Reinderien's user avatar
  • 65.3k
4 votes

Philips Hue Light Controller

Unused code This function was declared, but it does not seem to be used: def light(): If it is not used, it should be deleted. If it is used, it should have a ...
toolic's user avatar
  • 6,082
3 votes

Calculation of independence test statistic

Thank you for instrumenting the code. I'm ignoring the initial code and will just focus on the instrumented one. shadowing builtins ...
J_H's user avatar
  • 34.8k
4 votes

Compute damages and savings for motor insurance claims

I have created a simple dictionary comprehension code like this I do not think that means what you think it means, because your code doesn't have any comprehensions at all. It has some ...
Reinderien's user avatar
  • 65.3k
3 votes

Animating Lissajous curves with Python and matplotlib's animation library

For demonstration purposes I disregard the .gif generation, and especially disregard Jupyter. Notebooks tend to produce a scope swamp. System parameters? Throw them in the swamp. Loops, matplotlib ...
Reinderien's user avatar
  • 65.3k
2 votes
Accepted

How to structure and write exchangable calculation models (in python3 modules)?

I don't understand the "interchangeable modules" question. I can't find a clear example in your code of two different approaches that are able to be substituted one for the other. I think ...
Reinderien's user avatar
  • 65.3k
5 votes

python: Create a histogram from multiple large JSon Files

Using mind-reading (and a stray comment from the OP), I can tell that this: 60*int(s[11:13]) + int(s[14:16]) is a string-formatted time. Because the OP is no ...
Reinderien's user avatar
  • 65.3k
3 votes

Vectorizing a working custom similarity function further using numpy

The comprehension statements are far too long and complicated and need to be broken up (but shouldn't exist at all). The easy vectorisation pass involves replacing all of the comprehensions with ...
Reinderien's user avatar
  • 65.3k
2 votes
Accepted

Using arrays more effectively with numpy

Gosh, this took a very long time to research and write. Apparently this is an implementation of Computing complete Lyapunov functions for discrete-time dynamical systems. It's a nasty calculation. ...
Reinderien's user avatar
  • 65.3k
1 vote

Simple snake game in Python

UX It is not obvious what the user should do when the GUI opens up. You should display some simple instructions in the GUI, such as: ...
toolic's user avatar
  • 6,082
3 votes

Managing file paths in a python Data Science project

JSON usage JSON was never developed as a human-readable config language. Yes, a lot of popular projects (esp. in JS ecosystem) decided to abuse it for such purposes, and it has bitten almost everyone ...
STerliakov's user avatar
4 votes

Snake game from the viewpoint of the snake

UX It is not obvious what the user should do when the GUI opens up. You should display some simple instructions in the GUI, such as: ...
toolic's user avatar
  • 6,082
4 votes

Find maximum area of rectangles within a histogram

Implementation It's not clear why you defined a class with no data members and only one function member. This would be much simpler as a plain function. The various commented-out assignments to ...
Toby Speight's user avatar
  • 81.7k
2 votes

Table tennis tournament scoreboard

Input validation This assumes sets_player1 can not be equal to sets_player2: ...
toolic's user avatar
  • 6,082
4 votes
Accepted

Table tennis tournament scoreboard

It looks quite good. A few small things: Since in parse_match you don't plan to handle the ValueError except by raising a more ...
Chris's user avatar
  • 1,576
1 vote

Taxicab distance from path specification (Advent of Code - Day 01)

We don't need loc_found as a variable; we can use duplicate_location for that, since it starts off as ...
Toby Speight's user avatar
  • 81.7k
3 votes

Managing file paths in a python Data Science project

argparse When I run the code without passing a command-line argument, it dies badly with error messages. It would be better if it died with a helpful message which clearly shows the intended usage. ...
toolic's user avatar
  • 6,082
3 votes

Mean, median and mode GUI

GUI When I run the code, the Tk window is too narrow, and I can't see full window title. Also, it would be helpful to display some simple instructions for the user. Input checking When I enter a word ...
toolic's user avatar
  • 6,082
3 votes

N-D Kalman Filter in Python + Numpy

Ignore for the moment the cookbook and filterpy.kalman, and let's assume that your implementation is nominally numerically correct. You had already done one manual check to validate that this is ...
Reinderien's user avatar
  • 65.3k
5 votes

Python loading image into memory (numpy arrays) from database bytes field fast

matricies is not a word. A crucial step in your pipeline, and one you have only implied, is the actual blob-loading from MongoDB. Let's assume that you use pymongo. ...
Reinderien's user avatar
  • 65.3k
3 votes

Wrangling and reading several xlsx files from sftp server and concatenating them into a single dataframe

I don't think that these aliases: from datetime import datetime as dt, time as ti, timedelta as td are well-advised; just use the full type names. Though I can't ...
Reinderien's user avatar
  • 65.3k
2 votes
Accepted

Infinite 2d block world (2d minecraft) with chunk system, physics and slower loading

I have managed to fix the world.load_nearest_chunk method and now I get over 60 fps! This is how i did it: 1 - pregenerate the ...
coder's user avatar
  • 121
5 votes

Infinite 2d block world (2d minecraft) with chunk system, physics and slower loading

A few things jump out: Don't calculate the chunks lists. Based on the player's movements, you know which chunks might need to be loaded and which ones can be dropped. For example, if the player moves ...
RootTwo's user avatar
  • 10.2k
3 votes

Pandas calculation speed of stock beta on many dataframes

Whenever you write section delimiters like ...
Reinderien's user avatar
  • 65.3k
3 votes

Student report card management Python program

Move all of your code into functions. This stage: ...
Reinderien's user avatar
  • 65.3k
3 votes

Argument Order To Determine Order Of Output (Python; `attrs`)

Attrs You need to code your own __init__ function to be able to use **kwargs and get the argument order. Otherwise, attrs will ...
RootTwo's user avatar
  • 10.2k
3 votes

Pandas rolling evaluation

I don't think you should do this. For your demonstrated AAPL just do something like ...
Reinderien's user avatar
  • 65.3k
4 votes

ssh key install

Briefly, this - ...
Reinderien's user avatar
  • 65.3k
4 votes

ssh key install

Some suggestions to improve your code: Unpacking Instead of using indices to refer to the items in i, you can directly unpack them. This will make your code more ...
Green grün 绿色 vert зеленый's user avatar

Top 50 recent answers are included