# Questions tagged [numpy]

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

686 questions
Filter by
Sorted by
Tagged with
27 views

### Spectrograph using array-of-slice-references

I've written a working and complete proof of concept that shows a spectrograph in Matplotlib. I want to nail down this proof of concept before I continue with development, and I'm not thrilled with ...
40 views

### Resource reservation system

I'm using a function to determine if resources can be used again or not. This is the numpy array I'm using. ...
85 views

### TicTacToe: If an error messages do not appear straight away

I am fairly new to Python and have tried to create a tic tac toe game that is completely automatic, where you can see if a player1 has an advantage if you let it ...
153 views

### Active Brownian Motion

I am attempting to write a Python code to simulate many particles in a confined box. These particles behave in such a way that they move in the box in straight lines with a slight angular noise (small ...
110 views

### Vectorized numpy co-occurrence matrix generation

Update The implementation did not consider multiple occurrences of a same word, and self word occurrences. For instance when stride=2 and the word at the position is ...
114 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 ...
87 views

### SineCosine Wave

As a beginner this is my first code. Any comments? ...
122 views

### Implement vectorization instead of nested loops on dataframe

I have a dataset ('sample_data.csv') of the form below: ...
119 views

### Counting Sequential Booleans

This function takes a list/array of booleans and converts them to an array that counts the number of either True/False values found next to each other. I'd like to see this optimized for performance. ...
307 views

### Slow copying of memmap array to numpy array

I have multiple binary (structured) file, each of 2GB, which I am currently reading in pair, using memmap to cross-correlate the same. I want to minimise the time required by this IO process, in the ...
38 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 ...
75 views

### Can this numpy code be vectorized?

I've written the following function to produce n realizations of a CIR process for a given set of parameters: ...
36 views

### Converts Pandas and Numpy into Dictionary and Converts back to original format for data split

I'm trying to refactor some code so that it does not have so much repetition to it. What I'm trying to do is create an input for a multiple channel/input neural network. The features that are being ...
1k views

### Cython with variable-length arrays

Dynamically growing arrays are a type of array. They are very useful when you don't know the exact size of the array at design time. First you need to define an initial number of elements. (Wikipedia) ...
67 views

### Searching in Numpy

I have sorted ascending number if you do abs(arr) in below code, I am trying to search for index where sign got changed from negative to positive. Wrote this below code, but for some reasons, I ...
30 views

### Populating 2 columns in a dataframe with frequencies from a dictionary of dataframes

I have a pandas dataframe, my_calculation, that is a Cartesian product of 4 different categories (Name, Freqset, Formula, and Location) and two additional ...
123 views

### Inplace operations for a class with numpy-style docs

In pandas lot's of methods have the keyword argument inplace. This means if inplace=True, the called function will be performed on the object itself, and returns ...
36 views

### Pandas : Apply Merge operations from a column

I have a data frame, which contains three columns: ...
116 views

### Better way to calculate double-scattering diffraction using cartesian product of arrays?

This script calculates points in reciprocal space for hexagonal 2D lattices, then uses the cartesian product from itertools to add each vector from one lattice to all of the vectors of the other in ...
184 views

### Print a array of size n*n, with borders as 1's and fill rest of element with 0's

Assessment Question: Print an array of size n*n, with border as 1's and rest of the element as 0's. Sample Input: 5 Sample Output: ...
27 views

### Moving mean square error between 2 arrays, 'valid', where they fully overlap

You can find my original post here on SO. I was very surprised that I couldn't find a pre-coded function doing a mean square error between a signal (array A, size a) and a pattern (array B, size b<...
27 views

46 views

### Numpy array slicing/reshape/concatination

I'm sure my question exists on the internet, i just don't know the right formulations. I have a data-sample as input for a NN. This sample has the shape (1, 8, 28, 80). Basically it is 80 timesteps ...
68 views

### Image color-moment extractor [closed]

I was just wondering if there is a way to speed up the performances of this for loops in Python. I'm trying to process an image to get the color-moments without using libraries. It takes about 12sec ...
213 views

### Implementing a Steepest Descent Algorithm

I am teaching myself some coding, and as my first "big" project I tried implementing a Steepest Descent algorithm to minimize the Rosenbrock function: $$f(x, y) = 100 (y - x^2)^2 + (1 - x)^2$$ The ...
247 views

### Jupyter notebook style help + code suggestions for pandas

I wanted to open source some code to scrape and analyze publicly-filed stock buys and sells from U.S. senators. I'm not familiar with code style for Jupyter notebooks or pandas in general. Would it be ...
479 views

### Efficient numpy array manipulation to convert an identity matrix to a permutation matrix

Task I want to be able to generate the permutation matrix that splits a 1D array of consecutive numbers (i.e. even, odd, even, odd, even, odd, ...) into a 1D array where the first half are the evens, ...
72 views

### Applying gaussian blur on RGBA images

I designed the code and it works quite well for images of lower res. However my program takes a lot of time and ram to display higher res images (occupies 2GB RAM for 4k images and takes 20 minutes). ...