I want to connect different shapes of ndarrays with new axes added.

Asked 1 years ago, Updated 1 years ago, 63 views

How do I connect different shapes of ndarrays with new axes added?

For example, a two-dimensional array of two different shapes (columns equal)

a=array([1,1,1,1],
           [1,1,1,1],
           [1,1,1,1]])

b = array([2,2,2,2],
           [2,2,2,2]])

Connect vertically and

array([[1,1,1,1],
        [1,1,1,1],
        [1,1,1,1]],
       [[2,2,2,2],
        [2,2,2,2]]])

I would like to create a three-dimensional ndarray array like this.
When connected by np.vstack, no new axes are added, so the connected ones become a two-dimensional array.

Specifically, when reading image data in ndarray format as a data set for classification, I want to combine the 256-dimensional (this is different for each class) *? (but each class has a three-dimensional array for easy index access).

I look forward to your kind cooperation.

python numpy

2022-09-30 18:56

2 Answers

https://stackoverflow.com/questions/3386259/how-to-make-a-multidimension-numpy-array-with-a-varying-row-size/43463348#answer-3386428

is a similar question, but

It's optimized for homogenous arrays of numbers with fixed dimensions. If you really need arrays of arrays, better use a nested list

As stated,
NumPy guarantees fast operations and flexible operation by optimizing a fixed-size, same-dimensional array of numbers. Simply put, NumPy is meaningless to use if that assumption is broken.


2022-09-30 18:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.