Questions tagged [numpy]

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

86 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10
votes
0answers
174 views

Population dynamic simulation on biological information maintenance 2

This question is the follow-up to this previous question. Background Using this simulation I investigate a system in which enzymes proliferate in cells. During the replications of enzymes, ...
10
votes
1answer
1k views

Parallelizing some model fitting code using multiprocessing

I'm trying to refactor some code for fitting parametric models that are defined symbolically using Theano. My goal is for all models to expose a common interface so that, as far as possible, they can ...
7
votes
0answers
62 views

Find indices using for loop

I should estimate the effect of B fields on particle deflection using \$F=V \times B \times Force\$. I have a 2D mesh with \$n_x\$ and \$n_y\$ which show the number of points in each direction. \$B\$ ...
6
votes
0answers
66 views

Numerical integration in cython

I have a set of nested functions that I need to call multiple times. I know scipy.quad is pretty fast, but I will need to call the integrator recursively and want ...
6
votes
0answers
2k views

Calculating T-Test within Large Pandas Dataframes

The below code runs a t-statistic within a large dataframe (rnadf) based on masked values from another dataframe (cnvdf_maked). ...
6
votes
0answers
273 views

Summing 2D NumPy array by multiple labels

Each element of the array is a coordinate (x, y). Each coordinate has two labels. Goal: sum the elements that have the same two labels. How can ...
5
votes
0answers
120 views

Cubic spline interpolation in Python from scratch

I implemented the cubic spline interpolation explained in https://en.wikipedia.org/wiki/Spline_interpolation as a Python class. Of course, such an interpolation should exist already in some Python ...
5
votes
0answers
1k views

Plotting the Mandelbrot set at different zoom levels

I'm interested in making an animated movie of a zoom in on a part of the Mandelbrot set. My code works well for a few zooms, but upon trying to zoom in quite far, I find that the fractal becomes "...
5
votes
0answers
491 views

Calculating complex exponential numbers using OpenMP in Cython

I am trying to create a function that can either beat numexpr or perform comparably for the vectorized mathematical operation ...
4
votes
1answer
66 views

PyTorch Vectorized Implementation for Thresholding and Computing Jaccard Index

Update 1: I managed to speed up the script by 100s using PyTorch logical and and or. However, this operation is only supported ...
4
votes
0answers
422 views

numpy 2d array anti diagonal averaging

The following piece of code averages the ante-diagonal elements of a 2d array x of size (m,n) with, for my purpose, m > n. ...
4
votes
0answers
1k views

Pandas/Numpy statistical odds ratio test

I'm looking for a faster way to do odds ratio tests on a large dataset. I have about 1200 variables (see var_col) I want to test against each other for mutual exclusion/ co-occurrence. An odds ratio ...
4
votes
0answers
1k views

Applying hysteresis to a signal

Using python 3.6. I have written this code (below) to apply hysteresis to a signal (a numpy array). My aim was to create a function that didn't require any loop to remember the previous state of the ...
4
votes
0answers
533 views

Color image classification and labeling algorithm

I have some code I've been using to de-noise some images and then label all unique and contiguous elements. The function zoneMap() de-noises the image by picking a ...
4
votes
0answers
204 views

Finding where column slices of elements in multi-dimensional array are equal

Skippable Intro: I have a dataset that corresponds to an observed time-series. The dataset is organized into a dictionary - which contains an array of years, an array of months, an array of days, an ...
4
votes
0answers
2k views

Reducing memory consumption for Numpy array

I'm running the following code using numpy arrays, I get a MemoryError in Ubuntu, while the same code runs on Mac OSX. (Pagination is automatically setup in Mac) This process consumes around 30 GB. ...
4
votes
0answers
437 views

Find the closest parametric values corresponding to a BSpline's control points

On a curve generated by scipy.interpolate.BSpline I want to find the closest parameters relative to each control point, so that the given parametric range is ...
4
votes
0answers
807 views

2-D Kalman Filtering in Python using Numpy

I am practicing Kalman filtering and wrote a short python class that uses Numpy to calculate the 2-D kalman filter for position and velocity along the X axis: assume that the object is only moving ...
4
votes
0answers
2k 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 ...
4
votes
0answers
184 views

Simple Stateful LSTM example with arbitrary sequence length

I'm trying to make a simple example showing how to create a RNN with Keras that accepts as input a sequence of arbitrary length. In my example, the LSTM is trying to classify whether a sequence has ...
4
votes
0answers
478 views

Customizable Multi-Agent Predator/Prey Simulation

I am trying to create a highly customizable "battle simulator". The default setup is a predator/prey relationship (no births); however, I am trying to create code such that it's easy to add and ...
4
votes
0answers
356 views

Plant/Residue Detection project, How to structure it?

Introduction I have wanted to develop this project for more than two years. I just started writing it a couple days ago. I use it to detect plant or residue pixels in crop row images but it provides ...
4
votes
0answers
394 views

Python Code For Drawing a Fractal Tree using pyglet

So I've just finished doing a coding challenge that involved drawing a fractal tree. Instead of doing it recursively(which is what I did initially but it proved to be to slow for branches greater than ...
4
votes
0answers
207 views

Generalized NumPy reshape function to imitate einsum syntax

I often perform a lot of reshape(), transpose() or squeeze() operations on ...
3
votes
0answers
37 views

Implementing a tic tac toe board in python

This is my attempt at making a class to represent a game board for tic tac toe. I normally hate while loops but I used one because I cant seem to make the ...
3
votes
0answers
65 views

Optimising Probabilistic Weighted Moving Average (PEWMA) df.iterrows loop in Pandas

I'm implementing the Probabilistic Exponentially Weighted Mean for real time prediction of sensor data in pandas but have issues with optimising the pandas notebook for quick iterations. Is there a ...
3
votes
0answers
24 views

TensorFlow regressor to predict probability of winning, given a current score

This is a TensorFlow regressor that tells me that if you get x score, you will have x% to win a game in x game(game is not important). Doing this as a project to learn tensorflow. ...
3
votes
0answers
34 views

N-D Kalman Filter in Python + Numpy

Just implemented this Kalman Filter in Python + Numpy keeping the Wikipedia notation It's a pretty straightforward implementation of the original algorithm, the goals were develop skills related to ...
3
votes
0answers
347 views

Local maxima 3D array python

I'm trying to find the local maxima in a 3D numpy array, but I can't seem to find an easy way to do that using numpy, scipy, or anything else. For now I implemented it using ...
3
votes
0answers
58 views

Locality Sensitive Hash (similar to k-Nearest Neighbor), in Python+Numpy

I've tried implementing Locality Sensitive Hash, the algorithm that helps recommendation engines, and powers apps like Shazzam that can identify songs you heard at restaurants. LSH is supposed to run ...
3
votes
0answers
62 views

Computing Doppler delay on a meshgrid

Objective Plot the contour of the iso-doppler and iso-delay lines for a transmitter-receiver reflection on a specular plane. Implementation This Doppler shift can be expressed as follows: $$f_{D,0}(...
3
votes
0answers
60 views

Minimization problem solving and its step limits

I am trying to solve the following minimization problem: $$ \min\lvert\lvert{x}\rvert\rvert_1 + \beta\lvert\lvert{x}\rvert\rvert^2_2 s.t. \sum_{m = 1}^M (y - \lvert{c}^{H} . x\rvert^2)^2 \le \epsilon ...
3
votes
0answers
782 views

Distance transform on image using NumPy

I would like to find the find the distance transform of a binary image in the fastest way possible without using the scipy function distance_transform_edt(). The ...
3
votes
0answers
946 views

Better way to set number of threads used by NumPy

Background When NumPy is linked against multithreaded implementations of BLAS (like MKL or OpenBLAS), the computationally intensive parts of a program run on multiple cores (sometimes all cores) ...
3
votes
0answers
68 views

Variable bit length lossy floating point compression

I am implementing a new compression algorithm for the weights of a neural network for the Leela Chess project. the weights are roughly 100Mb of ...
3
votes
0answers
65 views

Data set generation with Python and Matplotlib

I want to use Python and Matplotlib to create a data set of images. I want to do this by transforming the plot to a numpy matrix. At the moment it takes about 0.1 second to generate 100 images of size ...
3
votes
0answers
90 views

Searching for the location of a sub-image within an image

I have a number of images that were cropped and their backgrounds removed. I've tried to write a function that will search the original unmodified image for the cropped image so that I can restore the ...
3
votes
0answers
112 views

Merging bin-data via a bin count threshold

When performing a chi-squared test, one takes the square of the differences of the expected counts per bin and observed counts per bin, and divides these per-bin differences by the expected counts per ...
3
votes
0answers
58 views

Numpy versus Theano GPU parallelization

I am learning Theano to accelerate my image processing functions. As a start, I am trying to reimplement the function to turn images from colors to black and white (with the same number of channels): ...
3
votes
0answers
42 views

Deriving incremental feature representations for bit flips

Given a boolean 3D matrix and a set of actions specifying bit flips at certain positions, a set of resulting matrices can be obtained, one matrix for each action, as if executing each bit flip ...
3
votes
0answers
3k views

Reading a csv file and making a histogram in Python using NumPy and Matplotlib

I have written the following code which reads a csv file that contains a bunch of words and their sentiment value. Words like abandon may have a value of -1, while words like progress and freedom have ...
3
votes
0answers
246 views

Applying Scikit-Learn Linear Kernel with a generator for low memory pressure

matrix = # a sparse matrix of TFIDF vectors - 28458x3218988 My aim was to create a similarity matrix comparing all documents to all documents using ...
3
votes
0answers
434 views

pandas time-based qcut

I have a dataframe pairs where each row is a transaction with corresponding price and date. Now, I need to assign each transaction to a quintile (add a new column), ...
3
votes
0answers
117 views

Simple finite difference employing Maccormack technique

I am relatively new to programming and while I am fairly comfortable with the math, I cannot say with confidence that I feel the same way with programming. Anyway here is a simple finite difference ...
3
votes
0answers
132 views

Speed up a Gibbs sampler with Cython

I have implemented a Gibbs sampler to generate textured images. According to the beta parameters (array of shape(4)), we can generate various textures. Here is my ...
3
votes
0answers
347 views

Cythonized version of FDCT (fast discrete cosine transform) function, ported from Java

This is my Cython code for an FDCT function (invoked here): ...
2
votes
0answers
46 views

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

Setup: I have ~30 parameters (dependent variables) measured simultaneously along a common time axis with ~1Hz resolution (independent variable). I need to calculate bin averages for all parameters, ...
2
votes
1answer
52 views

Trapezoidal rule for set of data

Here is the question from the book of Mark Newman-Computational Physics Exc 5.1 a) Read in the data and, using the trapezoidal rule, calculate from them the approximate distance traveled by the ...
2
votes
1answer
50 views

Select optimal piecewise regression fit

I'm making a program which fits a piecewise linear regression with up to 4-5 breakpoints in the data, and then deciding how many breakpoints is best to prevent over and underfitting. However, my code ...
2
votes
0answers
47 views

Python list operation - merge adjacent cubes into minimum number of shapes

I am hoping to find a way to make the process a lot faster. The lists are made of rows of 6 numbers, i.e. [[float] * 6, ...]. The intent is to pass a list of cube ...