All Questions

Tagged with
Filter by
Sorted by
Tagged with
3
votes
1answer
38 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 ...
0
votes
0answers
39 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 ...
2
votes
0answers
25 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 ...
3
votes
0answers
38 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 ...
0
votes
1answer
29 views

Slow calculating sum of individual cells of matrix

I have a 3-D array in numpy, of dimensions 3000 x 2000 x 8 I need to modify the cells of the array so that each cell will contain the sum of all cells above and left of it, inclusive the current cell. ...
2
votes
0answers
27 views

Convolution layer using numpy in python

I'm trying to make a CNN in python using numpy. I have a finished product but it seems that it can be improved. On testing the convolutional layer is the biggest bottleneck ...
2
votes
1answer
61 views

Efficient Comparison Of Two Images Using Numpy

I want to compare 2 images using numpy. This is what I have got so far. One of the outputs should be a white image with black pixels where pixels are different. I ...
4
votes
0answers
48 views

How to structure and write exchangable calculation models (in python3 modules)?

I do research and compare different numeric models to each other. Therefore, I want to easily switch out the numeric models in my simulations and evaluation code. Some models work in cartesian ...
7
votes
1answer
314 views

Genetic algorithm to guess coefficient of a polynomial

I have tried to code a genetic algorithm to guess the coefficients of a degree 4 polynomial. The information initially provided is values of y = f(x) for different x using the original polynomial. I ...
1
vote
0answers
88 views

Computing the angle between two vectors (vectorized) for small angles and with few copies

I am implementing a function that computes the angle between two vectors when given two n-dimensional arrays and an axis along which to operate. I want to do this with as few copies as possible, and ...
4
votes
1answer
80 views

Dataframe transformation to numpy ndarray takes ages to complete

I would like to transform my dataframe into an array of fixed-sized chunks from each unique segment. Specifically, I would like to transform the ...
0
votes
1answer
30 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
1answer
25 views

Removing Loop from Numpy XOR

I have been playing around with numpy and matplotlib. My little project was to create a scatter plot ranging from -1 to 1 on both X and Y, but where the shading is done with the XOR scheme. The ...
0
votes
0answers
27 views

Plotting 2 types of data from DataFrame with different colors

This is the task: ...
3
votes
1answer
85 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
59 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
64 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. ...
2
votes
2answers
61 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
751 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
41 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
75 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
133 views

Optimizing an implementation of the RKF method

This is an algorithm regarding the RKF method: ...
11
votes
1answer
162 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
50 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
439 views

Efficient NumPy sliding window function

Here is a function for creating sliding windows from a 1D NumPy array: ...
3
votes
0answers
31 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 -...
1
vote
0answers
37 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
1answer
54 views

Fast bruth force numpy array combination

I want to extract combinations of numpy arrays in that way: ...
2
votes
1answer
57 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
94 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
95 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 ...
1
vote
1answer
40 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
113 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: ...
1
vote
0answers
89 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
67 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
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 ...
1
vote
1answer
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 ...
3
votes
2answers
148 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 ...
3
votes
1answer
105 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
122 views

Implement vectorization instead of nested loops on dataframe

I have a dataset ('sample_data.csv') of the form below: ...
4
votes
1answer
111 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
278 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
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 ...
4
votes
1answer
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: ...
2
votes
0answers
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 ...
5
votes
2answers
905 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) ...

1
2 3 4 5
14