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 to extract an array of same dimension as the original array meeting a condition?

The question sounds very basic. But when I try to use where or boolean conditions on numpy arrays, it always returns a flattened array. I have the NumPy array P = array([[ 0.49530662, 0.07901 , -0.19012371], [ 0.1421513 , 0.48607405,…
Shew
  • 1,557
  • 1
  • 21
  • 36
1
vote
1 answer

visual understanding of rotation by numpy.rot90 for 3D and higher order arrays, ndarrays of dimension greater than 3

I'm trying to understand a single 90 degree rotation of a 3D numpy array and find it very hard to visualize (and thus to understand the rotation process itself). For a 2D case, it seems to be easy to do so. As an example, consider the below snippet…
kmario23
  • 57,311
  • 13
  • 161
  • 150
1
vote
2 answers

How to efficiently compare each pair of rows in a 2D matrix?

I am working on a subroutine where I need to process each row of a matrix and find which other rows are contained in the current row. For illustration of when a row contains another, consider a 3x3 matrix as below: [[1, 0, 1], [0, 1, 0], [1,…
1
vote
0 answers

'numpy.ndarray' object has no attribute 'sqrt'

I am trying to obtain the std of this output using numpy.std() [[array([0.92473118, 0.94117647]), array([0.98850575, 0.69565217]), array([0.95555556, 0.8 ]), 0.923030303030303], [array([0.85555556, 0.8 ]), array([0.95061728,…
MikeDoho
  • 552
  • 2
  • 5
  • 18
1
vote
1 answer

Iterating over successive 1-D slices along arbitrary axis of numpy array

I am writing a python package that performs various complex statistical analysis tasks along an arbitrary axis of an arbitrarily-shaped numpy array. Currently, so that the array shape and axis can be arbitrary, I just permute the array so the axis…
Luke Davis
  • 2,548
  • 2
  • 21
  • 43
1
vote
2 answers

Adding Numpy ndarray into dataframe

I would like to add a numpy array to each row in my dataframe: I do have a dataframe holdings some data in each row and now i like to add a new column which contains an n element array. for example: Name, Years Test, 2 Test2, 4 Now i like to…
quant
  • 33
  • 3
1
vote
1 answer

Time comparison of numpy argmax and sort functions

I am trying to find the column with maximum column-sum of a 2D matrix in numpy. For example: Let A = [[1, 2, 3], [0, 1, 4], [0, 0, 1]] The sums of each column is [1, 3, 8]. Therefore, 3rd column has the maximum column-sum. While trying numpy.argmax…
randomprime
  • 123
  • 4
1
vote
2 answers

What numpy structures are expected as inputs to use numpy.char functions?

Consider a numpy array of array of strings (at least my closest take on how to do that): ff = np.array([['a:bc','d:ef'],['g:hi','j:kl']]) print(ff.dtype)
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
1
vote
1 answer

Pad elements in ndarray using unique padding for each element

I am quite new to python and have read lots of SO questions on this topic however none of them answers my needs. I end up with an ndarray: [[1, 2, 3] [4, 5, 6]] Now I want to pad each element (e.g. [1, 2, 3]) with a tailored padding just for that…
Melron
  • 459
  • 4
  • 14
1
vote
3 answers

TypeError: only size-1 arrays can be converted

I am trying to convert the below to integers I have a variable p which is the below array([0.09641092, 0.02070604, 0.21679783, ..., 0.06453979, 0.02907993, 0.12129478]) I want to convert the numbers based on a threshold thres = 0.5 then convert p1 =…
Ian Okeyo
  • 299
  • 1
  • 4
  • 7
1
vote
1 answer

Numpy array: Function affects original input object as well

I am working at my personal image augmentation function in TensorFlow 2.0. More specifically, I wrote a function that returns a randomly zoomed image. Its input is image_batch, a multidimensional numpy array with shape: (no. images, height, width,…
Leevo
  • 1,683
  • 2
  • 17
  • 34
1
vote
1 answer

Having trouble summing along the third axis in Numpy

I am working on a program that takes a screenshot and saves the pixels in a Numpy Array with 3 axis (X, Y, and the RGB value itself) and cannot properly sum the last axis. I have searched up information on this topic, and although I have tried…
1
vote
0 answers

Is it possible to create a numpy.memmap of array of arrays?

I have a (4,) arrays that I want to save to the disk (The sizes I am working with can not fit into memory so I need to dynamically load what I need). However, I want to have that in a single numpy.memmap. Not sure if it is possible but any…
Kour
  • 33
  • 8
1
vote
1 answer

Python np.asarray does not return the true shape

I spin a loop on two sub table of my original table. When I start the loop, and that I check the shape, I get (1008,) while the shape must be (1008,168,252,3). Is there a problem in my loop? train_images2 = [] for i in range(len(train_2)): im =…
user11199189
1
vote
2 answers

What's the most efficient way to split up a Numpy ndarray using percentage?

Hi I'm new to Python & Numpy and I'd like to ask what is the most efficient way to split a ndarray into 3 parts: 20%, 60% and 20% import numpy as np row_indices = np.random.permutation(10) Let's assume the ndarray has 10 items: [7 9 3 1 2 4…
Tom Souza
  • 33
  • 7