Skip to main content

All Questions

Tagged with
3 votes
2 answers
106 views

Why is `array % 1` running 150% slower for smaller numbers than larger ones?

I would understand if numpy was smart enough to see that array % 1 gives a constant result (for that dtype), and that its runtime was independent of the input. I would also understand if runtime was ...
bers's user avatar
  • 5,385
1 vote
2 answers
85 views

Numba njit making function call involving long expressions extremely slow

I am writing a finite volume code to solve the inviscid, compressible Euler equations. As a part of this, I am performing what is known as the Cauchy-Kovalevskaya process. A code snippet is given ...
Siddharth Yajaman's user avatar
0 votes
1 answer
91 views

How to make python code fast for minimization?

The following code for minimization of a mechanical system works with no error. However, it is slow and to me there are unnecessary steps or loops that make it heavy! Would you make comment, and ...
Amir H. Fatollahi's user avatar
3 votes
2 answers
95 views

Numpy `np.prod`, `np.all` are slower than explicit algebraic operations

In the below experiments, explicit algebraic operations are faster than np.all and np.prod. What would be the reasons for that? import numpy as np import time N_ROWS = int(2e5) N_ITER = int(1e3) np....
Xavier's user avatar
  • 33
1 vote
0 answers
80 views

Why is my Cython code is not faster than NumPy, and how can I optimize it?

I'm trying to improve the performance of some of my code by using Cython. However, I'm getting basically the same performance as the NumPy version. When testing the same code with Numba, the results ...
R. Wilson's user avatar
1 vote
1 answer
106 views

Faster/parallelized way to merge multiple Numpy 3d arrays into one existing 3d array

I have a list containing 100 Numpy arrays/images with the shape (1024, 1024, 4). I have a second already existing Numpy array with the shape (1024, 102400, 4). I try to merge them into an already ...
user-cd's user avatar
  • 13
9 votes
1 answer
561 views

Using `numba` to speed up vectorization on very large `numpy` arrays

I originally had some code that operates on very large arrays using for loops. I wanted to see if I can speed it up with numpy and numba and tried 4 incremental steps to get it faster. Setup: from ...
Nathaniel Ruiz's user avatar
3 votes
1 answer
92 views

`numpy.astype` is slower than for loops for large arrays

I'm trying to use numpy to vectorize my code more and see performance benefits, but I was surprised to find that my code runs slower when using numpy. I'm doing a very simple test to compare "...
Nathaniel Ruiz's user avatar
3 votes
1 answer
149 views

Why does NumPy drastically slow down when I *decrease* the size of an array?

I have a 2D NumPy array, where the entries are random floats clustered tightly around 1.0, e.g. 1.015, 0.989, etc. The number of rows is n_rows = 10^4, and the number of columns is 2^13: n_rows = 10**...
Mr. Jefferson's Ghost's user avatar
0 votes
1 answer
30 views

Is there any way to replace integers with tensors in torch?

Say I have a = torch.tensor([[1,2,3],[2,1,3]]) And i want to replace integers 1,2,3 with [1,2,3],[4,5,6],[7,8,9] respectively. Meaning, i want result = torch.tensor([[1,2,3,4,5,6,7,8,9],[4,5,6,1,2,3,7,...
R. Alexander's user avatar
3 votes
2 answers
87 views

Python array still needed given that numpy now exists?

I learned about numpy arrays before discovering that python has the ability to work with arrays without numpy via "import array". The book "High Performance Python" describes ...
Hank's user avatar
  • 63
0 votes
0 answers
40 views

Performance of numpy matrix vector product on scipy.stats.qmc.Sobol vector when changing reshaping order

Solution at the bottom. I am trying to implement a Brownian bridge and want to speed up the path construction via numpy matrix multiplication, once the bridge is initialised. I am drawing data for 3 ...
Severin's user avatar
1 vote
1 answer
30 views

Difference in implementation based on whether a calculated expression is returned directly or first stored in a variable then returned

Is there a difference between the following two implementations based on computational performance and memory consumption? The difference is in storing an intermediate computation into a separate ...
Atharva's user avatar
  • 181
1 vote
1 answer
29 views

Optimize performance of function that creates buffer around non-zero values in numpy array

I have a function that takes a 2 dimensional array, and returns an array of same shape that has a 1 if the value in the original array is next to (horizontally, vertically, or diagonally) a non-zero ...
Samuel T's user avatar
2 votes
1 answer
52 views

Performance difference between C-Contiguous and Fortran-Contiguous arrays while using numpy functions

I was working around an example from a book compairing performance between C-Contiguous and Fortran-Contiguous arrays, where i observed that the Fortran-Contiguous array performed better for row-wise ...
Kshitiz Sharma's user avatar

15 30 50 per page
1
2 3 4 5
147