Task one:
import numpy as np a=np.asarray([[10,20],[101,201]]) # a=a[:,:,np.newaxis] # print(a.shape) # b= a.repeat([3],axis=2) # print(b.shape,b) image = np.expand_dims(a, axis=2) image = np.concatenate((image, image, image), axis=-1) print(image)
This understanding attached to the schematic diagram helps the visualization, there may be mistakes, I hope everyone will express their opinions!
Task two:
import numpy as np a=np.arange(1,10).reshape((3,3)) b=np.arange(11,20).reshape((3,3)) c=np.arange(101,110).reshape((3,3)) Print ( ' Axis = 0 \ n- ' , np.stack ((A, B, C), Axis = 0)) # stacked By List Print ( ' Axis. 1 = \ n- ' , np.stack ((A, B, C), Axis =. 1)) # rows stacked Print ( ' Axis = 2 \ n- ' , np.stack ((A, B, C), Axis = 2)) # stacked in each element
This blog is just to help you understand. Please also think a lot. If there are mistakes or you have a better learning method, you can comment. Welcome to share!
link:
https://blog.csdn.net/jacke121/article/details/80086866 (python single channel to 3 channel)
https://www.cnblogs.com/xzcfightingup/p/7598293.html (more numpy operations)