Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
a = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]配列を次の形式のnumpy行列に変換するにはどうすればよいですか?
a = [[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]
[[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]
?私はnp.bmat(a)無駄にしようとしました。これを行うと、2x6の行列が得られます。
np.bmat(a)
を使用np.arrayしてアレイを構築し、次にそれreshapeを正しい形状に成形します。
np.array
reshape
>>> np.array([[[[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]]]).reshape((4,4)) array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16]])