Questions tagged [numpy]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
90 views

Python function that shears image by n degrees while keeping the relationship between height and width

I am trying to find a method to shear/skew an image horizontally or vertically by n degrees (n ranges from -90 to 90 excluding the terminals) so that the result would meet the following conditions: ...
user avatar
2 votes
2 answers
41 views

Sampling from k circles with different radii

Description: I would like to sample n_points points from k circles whose radii and centers are given as lists. Note: This is my ...
user avatar
0 votes
0 answers
62 views

Python 3 OpenCV script that scans a giant picture to make a video

This is a Python script that I wrote completely by myself. Basically it scans a giant picture to make a video. They say one picture is worth more than a thousand words. Since a video contains ...
user avatar
0 votes
1 answer
40 views

Extract all elements of array with the given list of coordinates [duplicate]

I have to extract all elements of array with the given list of coordinates and insert into 2*298808 as position given in while loop How can I compress the code even more? ...
user avatar
  • 5
-1 votes
1 answer
50 views

How can i refactor python numpy code? [closed]

...
user avatar
  • 5
0 votes
0 answers
22 views

Creating an image from data, and slicing it into zxy tile service

I have some data that comes out of a grib file. The values in the grib file come out in shape of (721, 1440). Each value ...
user avatar
0 votes
1 answer
59 views

Stacking Z axis on multiple [1440x720] DataFrames (X, Y)

Each datum represents a point in a 1440x720 image of the globe, The values are 0-9. Each new layer is of a higher elevation. I need to structure a DataFrame in a ...
user avatar
5 votes
0 answers
81 views

Python 3 script to make photo collages

I have written a Python script that takes a list of filenames of pictures and generates a photo collage of them. This is my most complex project yet, and I have written it completely by myself (like I ...
user avatar
2 votes
1 answer
80 views

Replace nested for loops when assigning intial conditions in a 4-dimensional array

I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
user avatar
  • 69
2 votes
1 answer
62 views

type hinting/documenting/extension of a Cython lib

I've updated some of the type hinting/documentation in a lib called pygrib. The source documentation can be found here. The goal is to extend the ...
user avatar
1 vote
1 answer
67 views

Solving a 3D heat diffusion PDE

I am trying to solve a heat diffusion type PDE using a finite difference method. I would like to preface that I have seriously simplified the code. Just so that anyone who tries to help me, doesn't ...
user avatar
  • 69
2 votes
1 answer
68 views

dataframe mean outliers to NaN to derive a higher quality mean for area,speed,azimuth

I have some data that represents the area, speed(meters per second), and azimuth(rads) of a polygon. The objective is to determine the mean for each set of parameters. With that mean value, apply a ...
user avatar
1 vote
1 answer
39 views

numpy mean azimuth with functools.reduce

From the left to the right column calculating the mean azimuth, and using that mean value to calculate the subsequent columns mean value data (azimuth radians) ...
user avatar
3 votes
1 answer
49 views

Making a list of shades and styles for plots

For a section of a much larger program that generates plots, I am creating a list of styles that I can pull from to create a consistent format from plot-to-plot. It works as follows I have a list of ...
user avatar
  • 33
3 votes
1 answer
97 views

pandas dataframe of temps and numpy.linalg.lstsq

The problem is this. Forecast model data indicates at 0700Z the 1000 milibar temps will be -4C°. The forecaster knows that is incorrect, so they choose to make a correction. This correction should ...
user avatar
3 votes
1 answer
118 views

Vincenty's distance Direct formulae numpy

I've refactored a function from the pygc library used to generate the great_circle. The Vincenty's equation below can be found ...
user avatar
3 votes
1 answer
129 views

Numerical integration in Python involving four dimensions

I'm trying to obtain the following S2 from a given S1, $$ S2(i, j) = \sum _{k=0} ^i \sum _{l=0} ^j S1(k, i-k, j, l) e^{ -\sqrt{...
user avatar
4 votes
1 answer
66 views

3D to 4D surface fitter converter

I recently wrote this bit of code while trying to convert a 3D surface fitter to a 4D one. The solution works and I didn't want to leave the next guy to grind out the solution so I made the code as ...
user avatar
4 votes
1 answer
106 views

pandas conditions across rows and columns

Is there a better way to accomplish this? The function determines the Category for each row based on some conditions. Another set of conditions determines the <...
user avatar
1 vote
0 answers
39 views

Pandas Numpy Nvector to generate a storm track algorithm

I made previous post here, relating to this topic. The class uses now uses some additional 3rd party libs nvector & pygc. ...
user avatar
1 vote
1 answer
57 views

Multiple GeoJSON Feature Collections to a Pandas MultiIndex DataFrame

Edit: The end objective is to monitor the movement of severe weather, determine its vector and make a prediction. I'm working with a GeoJSON ...
user avatar
5 votes
1 answer
443 views

Laser physics simulation

This is for a computation for laser physics. The speed is quite slow, which seems to be delayed a lot by the three nested for loops with indices j,k, and l (with comments below). And the computation ...
user avatar
1 vote
1 answer
109 views

Minimum re-labeling to make an array as close as possible to another one

I have an array with integer labels in [0, n-1], say arr1=[1, 0, 3, 2] with n = 3. And then I have another array again with integer labels in [0, n-1], say arr2=[0, 0, 2, 3]. How can I find the ...
user avatar
  • 13
6 votes
1 answer
73 views

Calculating quantiles of timeseries data and then create a "fanplot"

My code is working properly, but I am looking for better approach in the calculation of quantiles and the finding of the data in the dataframe. ...
user avatar
  • 63
1 vote
1 answer
48 views

Exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series

The following numpy/python function computes exponentially-weighted moving mean and standard deviation of an irregularly-spaced weighted time series. I want to make it faster by getting rid of the ...
user avatar
3 votes
1 answer
65 views

Collatz conjecture with plots

I have an assignment where I write a Collatz Conjecture program for a series of starting values from 1 to N and make two plots: number of iterations vs starting value and computed numbers vs starting ...
user avatar
  • 215
1 vote
1 answer
121 views

Slicing multi index DataFrame into JSON object

I have a MultiIndex pd.DataFrame that I generated from a .txt that is forecast model data. ...
user avatar
0 votes
2 answers
60 views

Fastest way to find common events in 2 time series numpy arrays and calulate synchronisation statistic

Given 2 numpy arrays a1 and a2 (composed only of 0 and 1's), find index locations of all 0's in ...
user avatar
  • 162
1 vote
1 answer
239 views

Calculate a time weighted average of a feature

I'm trying to calculate a time weighted average of a feature (feat) based on previous rows by date for a given ...
user avatar
  • 133
1 vote
1 answer
97 views

Calculating all combinations from arrays AND (arrays OR floats)

Context: My question comes from needing to iterate different np.arange arrays. The main motivation is to calculate all the possible combinations between the arrays, ...
user avatar
  • 163
2 votes
1 answer
63 views

Calculate of the average of time discounted values

Given the current table: ...
user avatar
  • 133
2 votes
1 answer
43 views

find max value in islands defined by other vector

I have a vector of values vals, a same-dimension vector of frequencies freqs, and a set of frequency values ...
user avatar
  • 255
4 votes
1 answer
72 views

Path of a particle in a non-uniform B field

I have completed my project which simulates the path of a particle trapped in a device known as a magnetic mirror. I would like your thoughts and improvements on my implementation. Here is the code: <...
user avatar
  • 215
1 vote
0 answers
52 views

Solving a linear system with Gaussian Elimination

I decided to implement a solver for linear systems of equations based on the gaussian elimination and reduction to upper triangular form. The gaussian elimination is quite simple to implement but the ...
user avatar
  • 27k
4 votes
1 answer
101 views

Function to calculate the GC content variation in a sequence

I came across this BMC Genomics paper: Analysis of intra-genomic GC content homogeneity within prokaryotes And I implemented some Python functions to make this available as part of a personal project. ...
user avatar
2 votes
2 answers
108 views

How can I optimize this pairwise Euclidean distance search algorithm?

x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns. I need to get a matrix of Euclidean distances between each pair of rows from x and y. I ...
user avatar
1 vote
1 answer
80 views

using pandas and numpy to parse dirty .csv

I'm relatively new to Python have been writing for a few months now. I've started a Pandas Numpy project that starts with parsing large and somewhat sloppy formatted textfile, its not exactly csv but ...
user avatar
2 votes
1 answer
61 views

Generating a matrix with each row having normalized weights

I just asked this question over Stack Over Flow on how to improve my code and reposting it here as someone on Stack Overflow recommended this platform. I have written two python functions and they are ...
user avatar
3 votes
0 answers
56 views

Implementation of a crypto formula in Python

I need to implement in Python the formula in the image. The set B is a set of real numbers \$-1 \le t \le 1\$. Also, \$\mathbb{F}_2\$ is a set with the elements 0 and 1. \$y_i\$ is the \$i\$-th ...
user avatar
  • 139
2 votes
1 answer
155 views

Implementing histogram in python

I was trying to implement my own version of matplotlib's hist function and I came up with this: ...
user avatar
1 vote
0 answers
70 views

Using arrays more effectively with numpy

I previously posted some code I've been working on and had a fantastic answer, but as I didn't post the full code I was then unable to bring it all together using the much faster numpy implementation, ...
user avatar
  • 63
2 votes
1 answer
99 views

Calculating a function over a large array

I have written some code to determine an interpolation matrix over a grid of points. I originally wrote the code in matlab, where under the specified parameters it took just over 2 minutes. The ...
user avatar
  • 63
0 votes
1 answer
374 views

line-circle intersection [closed]

I have this code that generates a random line and a random circle. ...
user avatar
  • 109
2 votes
0 answers
190 views

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

I am looking for feedback on the function below to load a png image stored as bytes from a MongoDB into numpy arrays. ...
user avatar
  • 161
13 votes
5 answers
2k views

Iterate through two arrays calculating a statistic from indexes of zeros

I write a function which takes as input 2 arrays of zeros and ones ~8000 elements per array. Input array size is variable, can have much higher number of elements. The density of ones is expected to ...
user avatar
  • 162
3 votes
1 answer
152 views

Dynamically indexing numpy array

I want to create a function that takes a numpy array, an axis and an index of that axis and returns the array with the index on the specified axis fixed. What I thought is to create a string that ...
user avatar
  • 133
0 votes
0 answers
47 views

Vectorized code to find the position and length of runs of 1s in a bit matrix

I'm trying to write something like an adjusted run-length encoding for row-wise bit matrices. Specifically I want to "collapse" runs of 1s into the number of 1s in that run while maintaining ...
user avatar
  • 866
2 votes
0 answers
44 views

Vectorizing a working custom similarity function further using numpy

I am new to python, and even more new to vectorization. I have attempted to vectorize a custom similarity function that should return a matrix of pairwise similarities between each row in an input ...
user avatar
  • 121
2 votes
1 answer
252 views

Applying Minimum Image Convention in Python

I am computing pairwise Euclidean distances for 3-D vectors representing particle positions in a periodic system. The minimum image convention is applied for each periodic boundary such that a ...
user avatar
  • 21
3 votes
0 answers
42 views

Nearest neighbor search algorithm of quantization

I'm doing some research on Nearest Neighbor Search of quantization, where running speed is very important. As I've just started using Python, I wonder if the following code for multi-processes can be ...
user avatar

1
2 3 4 5
15