Questions tagged [numpy]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
7k views

Fuzzy c Means in Python

This is my implementation of Fuzzy c-Means in Python. In the main section of the code, I compared the time it takes with the sklearn implementation of kMeans. ...
2 votes
1 answer
83 views

Snake from the viewpoint of the snake

I wrote a little game of snake that where you can see the field in which the snake moves fixed and you can also see the "viewpoint" of the snake, which is basically calculating the positions ...
0 votes
1 answer
53 views

Get a "train or test" slicing elegantly after splitting

I am learning numpy, pandas, and sklearn for machine learning now. My teacher gives me code like below, but I guess it is ugly. This code is for splitting the data into training set and testing set, ...
1 vote
1 answer
49 views

Generate new column based on two columns of dataframe

I need to generate column a_b based on column a and column b of ...
0 votes
0 answers
44 views

Python image triangular mosaic creator

This is a Python script that turns images into "low-poly" art/creates a triangular mosaic from the image, I wrote this script completely by myself. In short, it takes a filepath to an image, ...
0 votes
0 answers
42 views

Deep Reinforcement Learning training on gym data

Related question: Extract the last row in a dataframe with a timestamp before some given time This is part of the code for Deep Reinforcement Learning training on a standards-based gym env. What I ...
-1 votes
1 answer
32 views

Numpy way of selecting indices of 2D numpy array if a condition met [closed]

I have a snippet of code to get indices of a 2D numpy array if the maximum value of that raw is greater than a number. ...
1 vote
0 answers
62 views

A collection of Python functions that fill a given region with rectangles

These are what I was working on in the last few days, I wrote a bunch of functions that fill a given region with rectangles of different colors. The functions can: Randomly split a region into sub ...
0 votes
0 answers
33 views

Python function that skews an image while preserving its aspect ratio using affine transformation

See this post for more details. I re-implemented my idea using affine transformations, and finally understood how transformation matrices are formed... Turns out it is stupidly simple, but nothing I ...
3 votes
1 answer
109 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: ...
2 votes
2 answers
43 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 ...
2 votes
1 answer
156 views

Ensuring performance of sketching/streaming algorithm (countSketch)

I have implemented what is know as a countSketch in Python (page 17: https://arxiv.org/pdf/1411.4357.pdf) but my implementation is currently lacking in performance. The algorithm is to compute the ...
0 votes
0 answers
63 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 ...
0 votes
1 answer
44 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? ...
-1 votes
1 answer
53 views

How can i refactor python numpy code? [closed]

...
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 ...
1 vote
1 answer
203 views

Fast brute force numpy array combination

I want to extract the combinations of numpy arrays in this way: ...
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 ...
5 votes
0 answers
109 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 ...
2 votes
1 answer
106 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 ...
2 votes
1 answer
67 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 ...
1 vote
1 answer
69 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 ...
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 ...
5 votes
2 answers
5k views

Project Euler Problem 11

Problem 11: In the 20×20 grid below, four numbers along a diagonal line have been marked in red. ...
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) ...
3 votes
1 answer
100 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 ...
3 votes
1 answer
52 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 ...
3 votes
1 answer
130 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 ...
3 votes
1 answer
132 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{...
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 ...
4 votes
1 answer
107 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 <...
3 votes
1 answer
67 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 ...
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. ...
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 ...
1 vote
1 answer
60 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 ...
5 votes
1 answer
476 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 ...
6 votes
1 answer
82 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. ...
1 vote
1 answer
53 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 ...
5 votes
1 answer
192 views

Bancroft's method implementation

Background I've written an algorithm to solve the three-dimensional Time Difference of Arrival (TDoA) multi-lateration problem. That is, given the coordinates of n ...
1 vote
1 answer
147 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. ...
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 ...
2 votes
1 answer
63 views

Calculate of the average of time discounted values

Given the current table: ...
1 vote
1 answer
107 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, ...
1 vote
1 answer
319 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 ...
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 ...
4 votes
1 answer
80 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: <...
1 vote
1 answer
48 views

Cleaning Netflix-style recommendation engine datasets

I am working on a portfolio project that deals with creating a Netflix-style recommendation engine for movies. This code is currently ran locally but I will need to upload it into Jupyter Notebooks ...
1 vote
0 answers
55 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 ...
4 votes
1 answer
121 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. ...
5 votes
1 answer
5k views

Implementation of the Householder Transformation

I implemented the Householder transformation in Python, so that I can later use it in a QR decomposition. Unfortunately I haven't found a good concise source for reading up on the algorithm. I am not ...

1
2 3 4 5
15