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
1
vote
2 answers

How can I select specific values from list and plot a seaborn boxplot?

I have a list (length 300) of lists (each length 1000). I want to sort the list of 300 by the median of each list of 1000, and then plot a seaborn boxplot of the top 10 (i.e. the 10 lists with the greatest median). I am able to plot the entire list…
egeorgia
  • 41
  • 1
  • 4
1
vote
1 answer

How to get the index of an numpy.ndarray

I would to print the images on index i but I get an error of only integer scalar arrays can be converted to a scalar index. How can I convert I to int for each iteration I have tried replacing images[i] with images[n] it worked but not the result I…
Biasi Wiga
  • 106
  • 9
1
vote
1 answer

Python use every element in ndarray as param for lambda function

I'm trying to calculate the vector basis for any transformation in R^n -> R^m. In order to achieve this I wrote lamba functions to represent the actual function. Some samples are: R2 -> R2: g1 = lambda x,y: np.array([2*x+y, x+2*y]) R3 -> R1: g3 =…
Peter
  • 1,844
  • 2
  • 31
  • 55
1
vote
1 answer

Sort vectors in np.ndarray

I'm new to python. This seems like a super easy problem but none of the similar answers I found were relevant to my case. I have an np.ndarray object, where every row represents a vector, like so: vectors = [[2, 0, 1] [1, 1, 2] …
Matheus Leão
  • 417
  • 4
  • 12
1
vote
3 answers

Array won't assign more than 8 characters in python

Array is acting weirdly, I have this code: a=np.array(['dfdfdfdf', 'gulf', 'egypt', 'hijazi a', 'gulf', 'egypt']) And I did this: a[0]="hello there my friend" Result was: array(['hello th', 'gulf', 'egypt', 'hijazi a', 'gulf', 'egypt'], …
John Sall
  • 1,027
  • 1
  • 12
  • 25
1
vote
2 answers

Create a new numpy array from list or tuple

When creating new numpy arrays, you can make them like this: a = numpy.array((2, 5)) b = numpy.array((a[0] + 1, 10)) or like this: a = numpy.array([2, 5]) b = numpy.array([a[0] + 1, 10]) Which way is better?
LeopardShark
  • 3,820
  • 2
  • 19
  • 33
1
vote
0 answers

How do I turn a large multi dimentional numpy ndarray into a string without truncating and save it to .txt in python3?

I'm trying to convert a large image matrix (1280,720,3) in numpy ndarray format into a single large readable string, then save this string into .txt file. When I do this, the string gets truncated and cutoff automatically and I can not get the…
John Doenut
  • 185
  • 3
  • 11
1
vote
2 answers

Unable to plot scatter plot because of TypeError

I have a dataset, in which i will be using only a single column to apply kmeans clustering. However while plotting the graph, i am getting "numpy.ndarray". I tried converting to float, but still facing the same issue Dataframe: Brim 1234.5 345 …
anagha s
  • 323
  • 1
  • 4
  • 15
1
vote
2 answers

Is there a way to load a numpy unicode array into a memmap?

I am trying to create an array of dtype='U' and saving that using numpy.save(), however, when trying to load the saved file into a numpy.memmap I get an error related to the size not being a multiple of 'U3' I am working with python 3.5.2. I have…
Kour
  • 33
  • 8
1
vote
2 answers

Why I can't index a 2-d numpy.ndarray and assign new value

I wanna index a 2d ndarray and fetch a subset of this ndarray. Then I assign this subset ndarray with another ndarry which has the same shape with this subset ndarray. But the original ndarray is not changed. Here is an example.mat is not changed…
BAKE ZQ
  • 765
  • 6
  • 22
1
vote
0 answers

Problem with multiprocessing pool in python

In my python code there is a For loop which reads files from a large list of filenames, reads information from these files and then write this information to a Numpy.ndarray. I realized that this for loop is taking a lot of time to complete and I…
brownser
  • 545
  • 7
  • 25
1
vote
4 answers

How to construct a numpy array of numbers of powers of 2 more elegantly?

I would like to figure out how i can create this array without putting every single value in per hand. Is there a way how i can use the information that every value is the doubled value of its predecessor, except for the first? My Code is as…
R.K.
  • 13
  • 4
1
vote
1 answer

cannot reshape array of size (x,) into shape (x,y,z,1)

I'm trying to convert a numpy ndarray with a shape of (2200,) to numpy ndarray with a shape of (2200,250,250,1). every single row contains an image (shape: 250,250,1) This is my object: type(x_train_left) prints numpy.ndarray x_train_left.shape…
Yarden Rotem
  • 85
  • 12
1
vote
1 answer

How to generate a 3D grid of vectors ? (each position in the 3D grid is a vector)

I want to generate a four dimensional array with dimensions (dim,N,N,N). The first component ndim =3 and N corresponds to the grid length. How can one elegantly generate such an array using python ? here is my 'ugly'…
Dr. Thanos
  • 13
  • 2
1
vote
2 answers

Replace values in a 3d numpy array

There are those two numpy arrays: a = np.array([ [ [1,2,3,0,0], [4,5,6,0,0], [7,8,9,0,0] ], [ [1,3,5,0,0], [2,4,6,0,0], [1,1,1,0,0] ] ]) b = np.array([ [ [1,2], …
VnC
  • 1,936
  • 16
  • 26