When the np.concatenate function axis = 1, the output type question.

Asked 1 years ago, Updated 1 years ago, 96 views

When there is an array of two rows and three columns called gird = np.array ([[1, 2, 3, [4, 5, 6])

If you do np.concatenate ([gird, grid], axis=1), Why is the result

array([[1, 2, 3, 1, 2, 3], [4, 5, 6, 4, 5, 6] Does it work like this?

I think array([[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6] I think it should be like this

python numpy concatenation

2022-09-22 19:37

1 Answers

concatenate according to the numpy document:

Join a sequence of arrays along an existing axis.

(Interpretation) Join each array along axis.

Therefore

Therefore, np.concatenate ([grid, grid], axis=1) joins the sequence based on axis = 1. Illustrated as follows:

array ([[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6]]) If you want to make a array ([1, 2, 3, 4, 5, 6]), I think you should use stacks, not join.

flatten_grid = grid.flatten()
np.array([flatten_grid, flatten_grid])
np.stack((flatten_grid, flatten_grid))


2022-09-22 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.