Questions tagged [numpy]

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

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

Selecting a quantity from a list

I want to implement a function take_upto_n(A, n) such that for e.g. ...
-1
votes
1answer
48 views

Speed up calculation time of for loop in numpy [closed]

I am trying to calculate some values using numpy. Here is my code, ...
0
votes
1answer
49 views

Fill missing dates into array of np.datetime

Here is the problem: Given an array of a non-continuous sequence of dates. Make it a continuous sequence of dates, by filling in the missing dates. ...
1
vote
1answer
43 views

Finding distance between vectors of matrices

So here is the problem: Given 2D numpy arrays 'a' and 'b' of sizes n×m and k×m respectively and one natural number 'p'. You need to find the distance(Euclidean) of the rows of the matrices 'a' and ...
6
votes
3answers
431 views

Marking duplicate entries in a numpy array as True

So the problem is Find the duplicate entries (2nd occurrence onwards) in the given numpy array and mark them as True. First time occurrences should be False. And my solution is: ...
0
votes
0answers
40 views

Finding the Euclidean distance between the vectors of matrix a, and vector b

Here is the problem, Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of size m. You need to find the distance(Euclidean) of the 'b' vector from the rows of the 'a' matrix. Fill the ...
4
votes
2answers
67 views

Creating nxm index list of array a

Here is the problem: Given a numpy array 'a' that contains n elements, denote by b the set of its unique values ​​in ascending order, denote by m the size of array b. You need to create a numpy array ...
2
votes
1answer
19 views

Reducing running time of creating integration field in flow field algorithm (python)

The integration field needs to get recalculated every time the starting or goal coordinates change. I wanted to use the flow field algorithm for a problem that includes bigger mazes with changing ...
5
votes
3answers
125 views

Optimizing an implementation of the RKF method

This is an algorithm regarding the RKF method: ...
11
votes
1answer
155 views

From Hummingbirds to Ornithopters: Simulating the Aerodynamics of Flapping Wings

Ptera Software A Flapping Wing Aerodynamics Simulator Written in Python Motivation About a year ago, I became fascinated by how animals fly. As an aerospace engineering student, it surprised me that ...
3
votes
1answer
40 views

Generating multiple new arrays using numpy

Say I have the following two different states: state1 = [0, 1, 0, 1, 1] state2 = [1, 1, 0, 0, 1] And I want to generate n number of new states by only changing the ...
2
votes
1answer
196 views

Efficient NumPy sliding window function

Here is a function for creating sliding windows from a 1D NumPy array: ...
3
votes
0answers
28 views

Generating basic Fractals

Trying to generate fractals image with given IFS equations. I have two classes: Shape - Gives co-ordinate to form a shape. Ifs -...
0
votes
0answers
31 views

Reimplemented R function(s) is surprisingly slow

I reimplemented the functions https://rdrr.io/cran/fclust/man/RI.F.html, https://rdrr.io/cran/fclust/man/ARI.F.html and https://rdrr.io/cran/fclust/man/JACCARD.F.html of the R package https://rdrr.io/...
0
votes
0answers
25 views

Fast bruth force numpy array combination

I want to extract combinations of numpy arrays in that way: ...
2
votes
1answer
52 views

Performance issue in python- network creation based on the Euclidean distance with nested for loops is too slow

I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features ...
1
vote
1answer
93 views

decreasing solver speed

How can I decrease the time complexity and increase efficiency, without writing a new algorithm. My solution solves the majority of puzzles in a fast time, but for some difficult ones it can take over ...
2
votes
2answers
92 views

Downloading COVID data and uploading graphs

So this is a project I have been working on for the last few weeks. Just started learning Python. Started out with bash scripting and got the itch to learn more. Anyway code fetches covid-19 data from ...
0
votes
0answers
28 views

Reduce computing time of planning method (grid)

Has anyone an idea how to change the planning(self, sx, sy, gx, gy)-method to save computing time? I'm new to NumPy and don't know how to use it effectively yet, but I heard it could also be a good ...
0
votes
0answers
19 views

Optimized method of transfering numpy image arrays over localhost to web-tech UI for desktop UI

I have been doing testing to find the most efficient way to display numpy array images to a HTML, CSS, JS UI (specifically, with CEF Python). I mainly used the method explained here to do the numpy ...
1
vote
1answer
38 views

IDF Function with a list of list

I wanted to build a Inverse Document Frequency function, because in my opinion was not easy to do with scikit and I wanted also to show how it works for educational reasons. Also reading this question ...
5
votes
1answer
111 views

compare between two labels /objects -dominance rules

I have a function dominates() that seems to be the bottleneck of my algorithm (after profiling it). the function is as follows: ...
0
votes
1answer
39 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 ...
2
votes
1answer
42 views

Hardware driven data processing and ploting in need of better control flow

This is code for a measurement setup that receives a steady stream of UDP data, finds the trigger in one channel and operates on the data in the other channel to enhance the signal and remove noise, ...
1
vote
0answers
84 views

Multivariate Kernel Density Estimation for objects with missing values [closed]

I am trying to perform a certain numerical computation in Python with Numpy. More specifically, I am doing a multivariate Kernel Density Estimation (KDE) in a Euclidean space of dimension ...
5
votes
0answers
65 views

Neural Network Written in Python is Extremely Slow

I coded a basic feedforward neural network with all pure python with the exception of numpy in order to better understand how neural networks work. It works, but the only problem is it is extremely ...
2
votes
0answers
31 views

Optimize binary classification model

I've created binary classification model from scratch, just to understand intuition behind that. However when I compare my implementation to model from tensorflow/pytorch with the same parameters and ...
1
vote
0answers
23 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 ...
1
vote
0answers
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. ...
1
vote
1answer
82 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 ...
3
votes
2answers
129 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 ...
0
votes
0answers
49 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 ...
3
votes
1answer
74 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 ...
3
votes
2answers
87 views

SineCosine Wave

As a beginner this is my first code. Any comments? ...
3
votes
0answers
120 views

Implement vectorization instead of nested loops on dataframe

I have a dataset ('sample_data.csv') of the form below: ...
4
votes
1answer
97 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. ...
5
votes
0answers
194 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 ...
1
vote
1answer
29 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 ...
4
votes
1answer
72 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: ...
2
votes
0answers
35 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 ...
5
votes
2answers
602 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) ...
4
votes
1answer
65 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 ...
2
votes
0answers
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 ...
5
votes
1answer
101 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 ...
1
vote
1answer
35 views

Pandas : Apply Merge operations from a column

I have a data frame, which contains three columns: ...
1
vote
2answers
101 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 ...
2
votes
1answer
132 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: ...
2
votes
0answers
26 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<...
1
vote
0answers
21 views

Hermit Interpolation error check

I have done this code. But I am not sure that I have got the exact answer. I have never solved this kind of problem earlier. General form of a $2n+1$ degree Hermite polynomial: $$p_{2n+1} = \sum_{k=0}^...
7
votes
2answers
786 views

How to clean the indexes, and ideally not create an additional array

So I answered this question on SO and probably did someone's homework along the way. In the original question the OP has the answer variable and wants it split to ...

1
2 3 4 5
14