Questions tagged [numpy-ndarray]

Numpy Ndarray refers to the N-dimensional array type that describes the collection of the same type in the Python library NumPy. Use this tag for questions related to this array type.

Numpy Ndarray refers to the N-dimensional array type that describes the collection of the same type in the Python library NumPy.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html

3757 questions
20
votes
7 answers

Avoid overflow when adding numpy arrays

I want to add numpy arrays with datatyp uint8. I know that the values in these arrays may be large enough for an overflow to happen. So I get something like: a = np.array([100, 200, 250], dtype=np.uint8) b = np.array([50, 50, 50], dtype=np.uint8) a…
Thomas
  • 1,277
  • 1
  • 12
  • 20
17
votes
4 answers

Fill Bounding Boxes in 2D array

I have a 2D numpy array which looks like array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], …
a_parida
  • 606
  • 1
  • 7
  • 26
16
votes
2 answers

numpy.product vs numpy.prod vs ndarray.prod

I'm reading through the Numpy docs, and it appears that the functions np.prod(...), np.product(...) and the ndarray method a.prod(...) are all equivalent. Is there a preferred version to use, both in terms of style/readability and performance? Are…
dkv
  • 6,602
  • 10
  • 34
  • 54
15
votes
4 answers

(Keras) ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float)

I know this problem has been answered previously in the link below,but it does not apply to my situation.(Tensorflow - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float)) Both my predictor (X) and target…
RonSg83
  • 151
  • 1
  • 1
  • 3
14
votes
4 answers

How to convert a list of Numpy arrays to a Pandas DataFrame

I have a list of Numpy arrays that looks like this: [400.31865662] [401.18514808] [404.84015554] [405.14682194] [405.67735105] [273.90969447] [274.0894528] When I try to convert it to a Pandas Dataframe with the following code y =…
Yannick
  • 399
  • 3
  • 10
  • 16
14
votes
2 answers

Open / load image as numpy ndarray directly

I used to use scipy which would load an image from file straight into an ndarray. from scipy import misc img = misc.imread('./myimage.jpg') type(img) >>> numpy.ndarray But now it gives me a DeprecationWarning and the docs say it will be removed in…
Nic
  • 637
  • 2
  • 6
  • 19
12
votes
4 answers

What does layout = torch.strided mean?

As I was going through pytorch documentation I came across a term layout = torch.strided in many of the functions. Can anyone help me in understanding where is it used and how. The description says it's the the desired layout of returned Tensor.…
12
votes
3 answers

Python Numpy repeating an arange array

so say I do this x = np.arange(0, 3) which gives array([0, 1, 2]) but what can I do like x = np.arange(0, 3)*repeat(N=3)times to get array([0, 1, 2, 0, 1, 2, 0, 1, 2])
Runner Bean
  • 4,895
  • 12
  • 40
  • 60
11
votes
8 answers

Numpy: get the index of the elements of a 1d array as a 2d array

I have a numpy array like this: [1 2 2 0 0 1 3 5] Is it possible to get the index of the elements as a 2d array? For instance the answer for the above input would be [[3 4], [0 5], [1 2], [6], [], [7]] Currently I have to loop the different values…
Frederico Schardong
  • 1,946
  • 6
  • 38
  • 62
11
votes
4 answers

Compare a matrix against a column vector

Arrays 'A' and vector 'B' below are part of pandas dataframe. I have a large array A of form: 28 39 52 77 80 66 7 18 24 9 97 68 I have a vector B of form: 32 5 42 17 How do I compare pythonically each column of A against B. I am trying…
Zanam
  • 4,607
  • 13
  • 67
  • 143
10
votes
5 answers

Sort sounds by similarity based on timbre(tone)

Explanation I want to be able to sort a collection of sounds in a list based on the timbre(tone) of the sound. Here is a toy example where I manually sorted the spectrograms for 12 sound files that I created and uploaded to this repo. I know that…
Sam
  • 1,765
  • 11
  • 82
  • 176
10
votes
5 answers

How to multiply two 2D RFFT arrays (FFTPACK) to be compatible with NumPy's FFT?

I'm trying to multiply two 2D arrays that were transformed with fftpack_rfft2d() (SciPy's FFTPACK RFFT) and the result is not compatible with what I get from scipy_rfft2d() (SciPy's FFT RFFT). The image below shares the output of the script, which…
karlphillip
  • 92,053
  • 36
  • 243
  • 426
10
votes
2 answers

Python numpy array negative indexing

I'm a bit confused about the indexing of numpy. Assume the following example: >>> import numpy as np >>> x = np.arange(10) >>> x.shape = (2,5) >>> x array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) >>> x[0:-1] array([[0, 1, 2, 3, 4]]) >>>…
Ragadabing
  • 472
  • 2
  • 7
  • 14
9
votes
1 answer

Numpy Typehint with nptyping and Array in PyCharm

I try to use numpy with nptyping's Array to do my typehinting. I tried the following: enemy_hand: Array[float, 48] = np.zeros(48) I get an typerror: Expected Type 'Array[float, Any]', got 'ndarray' instead as far as I understand from this:…
NameVergessen
  • 598
  • 8
  • 26
9
votes
1 answer

Saving array as Geotiff using rasterio

I have the following numpy array: supervised.shape (1270, 1847) I am trying to use the following code to save it to GeoTIFF using rasterio: with rasterio.open('/my/path/ReferenceRaster.tif') as src: ras_meta = src.profile with…
GCGM
  • 901
  • 1
  • 17
  • 38