简体   繁体   中英

Restructuring the shape of an array in Python

I have an array with shape (64,64) in Python and I want to repeat these elements (three times) in the way that I could have an array with the shape (64,64,3). Any idea?

Probably the most simplest way to accomplish this here is by using numpy.dstack :

import numpy as np

b = np.((a, a, a))

where a was the original array (shape 64×64), and b is the new array (shape 64×64×3).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM