Relative Content

Tag Archive for pythonnumpynumpy-ndarray

np.zeros becomes faster with a very large array size

%timeit -n 1000 -r 7 np.zeros(100000000, dtype=bool) gives 4.22 ms %timeit -n 1000 -r 7 np.zeros(1000000000, dtype=bool) # 1 more zero = 10 times longer array gives 3.13 μs (not even milliseconds, microseconds!?) How can this be possible? Is this hardware dependent? python numpy numpy-ndarray

What explains these surprising timings in numpy?

I recently timed several different array allocation and initialization procedures in numpy. I however fail to interpret these timings. Here is a plot of my measurements (size of array in number of elements “n” for a given data type vs time of execution).

What explains these surprizing timings in numpy?

I recently timed several different array allocation and initialization procedures in numpy. I however fail to interpret these timings. Here is a plot of my measurements (size of array in number of elements “n” for a given data type vs time of execution).

ndarray a obtained from b.diagonal() has its value changed after the b modification

I’m a bit confused by the behavior of the below code and wondering if someone could shed some light on this. Basically, I have a matrix called mat which is a numpy ndarray. I get its diagonal using mat.diagonal() and assign it to the variable diag. I changed all diagonal values of mat to 100. Now I find diag has its values all changed to 100 too, which seems to indicate that diag directly references elements in mat. Yet, when I check the memory address of the first element in diag and compare it to that of mat, they are different. What’s the right way to look at this?

Place pixels on a grid

I have a two dimensional numpy array: myarray=[[0,0],[1,1],[2,2]]
I also have a grid of points: mygrid=[[70,70],[100,100],[30,30]]

Im trying to create a grid of circles

I have a circle “map”, which is basically an np.array() of coordinates which represent a circle with a fixed radius. I also have another np.array: screen=np.ones((dimensions of the screen), dtype=np.uint8). This is essentially a black canvas.