python - how to copy numpy array value into higher dimensions -


i have (w,h) np array in 2d. want make 3d dimension has value greater 1 , copy value on along 3rd dimensions. hoping broadcast can't. how i'm doing it

arr = np.expand_dims(arr, axis=2) arr = np.concatenate((arr,arr,arr), axis=2) 

is there a faster way so?

you can push dims forward, introducing singleton dim/new axis last dim create 3d array , repeat 3 times along 1 np.repeat, -

arr3d = np.repeat(arr[...,none],3,axis=2) 

here's approach using np.tile -

arr3d = np.tile(arr[...,none],3) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -