For example, I would like to do something like this
import numpy as np
A = np.array([[1,2,3],[4,5,6],[7,8,9]])
B = np.array([[1,1],[2,2],[3,3]])
C = np.zeros((2,2))
D = np.array([[A, B], [B.T, C]])
To produce a 5x5 ndarray with elements
1, 2, 3, 1, 1
4, 5, 6, 2, 2
7, 8, 9, 3, 3
1, 2, 3, 0, 0
1, 2, 3, 0, 0
一种方法是使用vstack
和hstack
:
D = np.vstack((np.hstack((A, B)), np.hstack((B.T, C))))
你几乎可以得到使用np.r_
这堆行和np.c_
这堆列
D = np.r_[np.c_[A, B], np.c_[B.T, C]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.