Skip to content
Advertisement

Tag: arrays

Numpy Array Conditional Operation Mask?

Suppose you have an array: a = [ 0,1,0] [-1,2,1] [3,-4,2] And lets say you add 20 to everything b = [ 20, 21, 20] [ 19, 22, 21] [ 23, 16, 22] Now lets say I want to add the resulting b to the original array a but only in cases where a < 0 i.e at the index

What does axis = 0 do in Numpy’s sum function?

I am learning Python, and have encountered numpy.sum. It has an optional parameter axis. This parameter is used to get either column-wise summation or row-wise summation. When axis = 0 we imply to sum it over columns only. For example, This snippet of code produces output: array([5, 7, 9]), fine. But if I do: I get result: 6, why is

Why are Python’s arrays slow?

I expected array.array to be faster than lists, as arrays seem to be unboxed. However, I get the following result: What could be the cause of such a difference? Answer The storage is “unboxed”, but every time you access an element Python has to “box” it (embed it in a regular Python object) in order to do anything with it.

python how to pad numpy array with zeros

I want to know how I can pad a 2D numpy array with zeros using python 2.6.6 with numpy version 1.5.0. But these are my limitations. Therefore I cannot use np.pad. For example, I want to pad a with zeros such that its shape matches b. The reason why I want to do this is so I can do: such

How to create a numpy array of lists?

I want to create a numpy array in which each element must be a list, so later I can append new elements to each. I have looked on google and here on stack overflow already, yet it seems nowhere to be found. Main issue is that numpy assumes your list must become an array, but that is not what I

Viewing .npy images

How can I view images stored with a .npy extension and save my own files in that format? Answer .npy is the file extension for numpy arrays – you can read them using numpy.load: One of the easiest ways to view them is using matplotlib’s imshow function: You could also use PIL or pillow: These functions aren’t part of the

Advertisement