Skip to main content

Questions tagged [numpy]

NumPy is the fundamental package for scientific computing with the programming language Python.

Filter by
Sorted by
Tagged with
10 votes
3 answers
2k views

I implemented this Rubik's Cube game in Python, using Canvas and Context2d for user interaction. This was mainly an exercise in &...
QuadmasterXLII's user avatar
4 votes
1 answer
367 views

Context & Background Please let me remind you that this project may involve original research; it is important to remember that all content on this site is subject to CC BY-SA 4.0. It is a breach ...
Konchog's user avatar
  • 355
5 votes
1 answer
155 views

Is there a way to significantly speed-up this code? I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
manifold's user avatar
  • 151
4 votes
3 answers
388 views

Recently I have been using numpy arrays, which have great utility via their broadcasting methods. I am attempting to write a useful public facing library, and this ...
Konchog's user avatar
  • 355
-2 votes
1 answer
106 views

I have two unidimensional numpy arrays in python, gs and ni. I want to intersect them but preserving the order in gs. When they have high cardinality this operation becomes so costly. Is there any ...
phyAlph's user avatar
6 votes
1 answer
460 views

I've written a Python script to solve a system of coupled differential equations and then use the results to solve an eigenvalue problem. The full problem is: \$\frac{d^2}{dr^2} K(r) = \frac{K(r)}{r^2}...
Amirhossein Rezaei's user avatar
9 votes
2 answers
516 views

A quick way to try to do this would be to use scipy.ndimage.map_coordinates, mapping radius to one axis of a rectangular array, and angle to the other, then summing along the radius axis. But, I think ...
uhoh's user avatar
  • 605
2 votes
1 answer
87 views

I'm solving a linear programming problem, made of many small problems with some common shared constraints, meaning that they are all together. Each individual unit has constraints unique to the unit ...
AReubens's user avatar
2 votes
2 answers
303 views

Follow up from this question. I have added a slower loading system that allows the main game to run faster but I still get under 30 fps with caves even if I allow the player to outrun the loading. I ...
coder's user avatar
  • 237
4 votes
1 answer
214 views

I'm trying to build a function that identifies those who are promoted into a list of jobcodes, or are promoted within that list of jobcodes. Initially I was using ...
Gage's user avatar
  • 41
1 vote
1 answer
105 views

This post is modified from this one: https://codereview.stackexchange.com/posts/292885/edit (Alternatives to iterrow loops in python pandas dataframes). I have a piece of code to calculate price ...
Laura's user avatar
  • 81
6 votes
2 answers
748 views

I have a piece of code to calculate price sensitivity based on the product and its rating. Below is the original data set with product type, reported year, customer’s rating, price per unit, and ...
Laura's user avatar
  • 81
2 votes
1 answer
58 views

I'm trying to capture profits and set a stop loss in my trading strategy. I want the stop loss to be set daily based on the past data and if the current price, i.e., price for the date falls below the ...
driver's user avatar
  • 222
5 votes
2 answers
319 views

I was trying to rewrite the Python code in MATLAB. The result is consistent. But, the MATLAB code is so slow. Any help would be appreciated. Ref python code link The MATLAB code written by me is as ...
138 Aspen's user avatar
  • 469
4 votes
1 answer
90 views

I posted this on Stack but since it's working code, it was suggested I post it here. I wrote this code to calculate ice thickness using the following equation from Stephenson, 2011. It's a daily ...
emmahaggerty's user avatar
3 votes
5 answers
2k views

This is a program to solve a differential equation numerically using Euler method. As of now, it is very slow, and I need to run 10000 Monte Carlo simulations. The differential equation is called ...
Jonathan Wick's user avatar
3 votes
1 answer
129 views

I have some scanning tunneling microscopy (STM) topography images that I need to flatten. I have found that for some data I need a 4th order polynomial, but in other cases a lower order works better. ...
uhoh's user avatar
  • 605
10 votes
3 answers
1k views

I have the following function that returns one of several functions along with their derivative for training neural networks. Can this function be improved and made more pythonic in any way? Are there ...
Atharva's user avatar
  • 185
4 votes
1 answer
142 views

We have a list of \$j \in \{1,\ldots,N\}\$ jobs with a processing time \$p_j\$ and a demand \$d_j\$ between 0 and 1. These are real numbers. Jobs require the fixed demand over the entirety of their ...
Titan's user avatar
  • 43
-1 votes
1 answer
63 views

I use the following code for a manual single value decomposition using numpy. Depending on the array I choose it sometimes works out well and I can verify the svd and sometimes it does not work out ...
LF-137's user avatar
  • 7
5 votes
2 answers
538 views

...
JustAnotherMind's user avatar
14 votes
1 answer
1k views

Good evening. I am studying mathematics at the moment, so I have little to no formal education in actual computer engineering. However, I am trying my hands at learning Python because I will need lots ...
francescoriccardocrescenzi's user avatar
4 votes
1 answer
121 views

I don't find an implementation in the library I work with of covariance function: I give a try at implementing it in Python: ...
SSSOF's user avatar
  • 43
3 votes
1 answer
118 views

Here is a code for a simple model of three phase two level inverter with constant DC voltage source and three phase RL load. ...
ppinha's user avatar
  • 51
2 votes
0 answers
83 views

This question is part of a series of posts about my massive Tic Tac Toe game with AI players, the previous question is: GUI Tic-Tac-Toe game with six AI players - part 1: the UI. This question ...
Ξένη Γήινος's user avatar
0 votes
2 answers
161 views

I wrote this code to indicate duplicated values. It actually works but I hope to know if there's another possible solution to optimize this process. Thanks. ...
peternish's user avatar
4 votes
2 answers
190 views

This is a NumPy script that converts BGR arrays to HSL arrays and back, without using OpenCV. Input and output values are arrays of 3 dimensions with values ranging from 0 to 1, the shape of the ...
Ξένη Γήινος's user avatar
5 votes
1 answer
102 views

Here is some code that generates the zero element of an Abelian sandpile model (ASM), for any given model dimensions, and then plots the result as a colormesh. Here is a wiki page explaining the ASM. ...
Eden Laika's user avatar
0 votes
1 answer
263 views

This function takes two inputs: A is 2D (N,5) while B is 1D (N). It tries to find the smallest ...
Sanyou's user avatar
  • 13
5 votes
3 answers
318 views

I'm thinking I implemented it optimally, but somehow it's much slower than what should be much slower, np.argmax(np.abs(x)). Where am I off? Code rationale & ...
OverLordGoldDragon's user avatar
2 votes
1 answer
210 views

I have created a LP function to help maximize a set of features. My first time playing with this library and also conducting LP. Variables: Number of features => X Number of Categories => Y ...
Kale 's user avatar
  • 23
4 votes
3 answers
165 views

I have a list with some nan values, out of which some are continuous, e.g.: list = [1, 2, 3, np.nan, np.nan, 6, 7, np.nan, 9, np.nan,np.nan,np.nan, 12] For some ...
Ranjan Kumar Sahu's user avatar
6 votes
1 answer
168 views

I am trying to write a basic Hartee-Fock program that computes the total energies and some properties of a molecule given as an input. The code uses Cython to statically compile the computationally ...
Hemanth Haridas's user avatar
3 votes
0 answers
183 views

Related This is a Python script that generates images using prime numbers up to a given positive integer, it generates prime numbers using the Sieve of Eratosthenes with some rudimentary Wheel ...
Ξένη Γήινος's user avatar
2 votes
0 answers
128 views

In mathematics, the Thue–Morse sequence, or Prouhet–Thue–Morse sequence, is the binary sequence (an infinite sequence of 0s and 1s) obtained by starting with 0 and successively appending the Boolean ...
Ξένη Γήινος's user avatar
6 votes
2 answers
561 views

I have written a code to calculate the MSD of some molecules. The code averages over multiple time origins (sliding time window) and over all the molecules. I have also made it do one extra thing: do ...
mjksho's user avatar
  • 61
2 votes
1 answer
174 views

I've been writing a small Rust module recently with the sole purpose of speeding up my Python program, which is a Conway's Game of Life simulation. The function written in Rust is called from Python ...
chubercik's user avatar
  • 123
2 votes
1 answer
103 views

As an exercise we should write a small Neural Network with the following structure: There should be additionally a bias for each layer and sigmoid should be used as the activation function. The ...
Leon0402's user avatar
  • 151
8 votes
2 answers
557 views

This is a very simple code that expresses a function in terms of Trigonometric Fourier Series and generates a animation based on the harmonics. I would like to know some ways to improve the ...
Lipe's user avatar
  • 83
1 vote
1 answer
94 views

I've amended a code for the Black-Scholes formula for European pricing options found here at the bottom of the page and fixed the math functions accordingly. Unlike the code on the website, mine has ...
Jessie's user avatar
  • 113
1 vote
1 answer
159 views

This code does exactly what I want it to, however I want to try and get rid of the nested loop to make it more pythonic. I have been trying to somehow use broadcasting, including playing with ...
WireInTheGhost's user avatar
3 votes
1 answer
190 views

The Github repository NM-Heston solves call option prices under the Heston 2-factor model using ADI splitting schemes. I am adapting the code to price options under the 3-factor Heston-Hull-White ...
Ruan's user avatar
  • 111
5 votes
1 answer
171 views

I am writing code that, at some later point, will be part of an academic multi-agent simulation of the learning process of car-sharing users and grid stability. This code deals with finding the price ...
Andreas Schuldei's user avatar
2 votes
1 answer
167 views

I've implemented the 2D ISING model in Python, using NumPy and Numba's JIT: ...
Amirhossein Rezaei's user avatar
2 votes
1 answer
116 views

I have an array of integers labels, for instance array([0, 1, 1, 2, 2, 2, 3, 3, 1, 4, 4, 1, 1, 0, 0, -1, -1]). The array can be ...
Mathieu's user avatar
  • 251
2 votes
2 answers
2k views

As you will probably notice very quickly from the code below, I'm not very experienced coder. Below is my attempt at valuating poker hands in Python. The code below may not be pretty but it seems to ...
Tom Mart's user avatar
2 votes
2 answers
197 views

I'm a hobby programer and I had an idea for pixelating images and I wrote it. I was wondering how would a better programer write the same function. I want to learn and I think that this would help me ...
FrankSintara's user avatar
9 votes
1 answer
4k views

...
ijknm's user avatar
  • 99
1 vote
1 answer
153 views

I tried to implement the mcolor colormap in the paper at page 8 to 10. I developed the code to process a image file and it works ok. Now, I want to adopt this image processing method to the camera ...
David Lin's user avatar

1
2 3 4 5
16