Skip to content

Instantly share code, notes, and snippets.

@rmwoods
Last active April 5, 2019 18:04
Show Gist options
  • Save rmwoods/9779c7fc3998bf5d7e6aac8aa3499ae4 to your computer and use it in GitHub Desktop.
Save rmwoods/9779c7fc3998bf5d7e6aac8aa3499ae4 to your computer and use it in GitHub Desktop.
a = np.arange(20).reshape(4,5)
#array([[ 0, 1, 2, 3, 4],
# [ 5, 6, 7, 8, 9],
# [10, 11, 12, 13, 14],
# [15, 16, 17, 18, 19]])
b = np.repeat(a,2).reshape(*a.shape,2)
#array([[[ 0, 0],
# [ 1, 1],
# [ 2, 2],
# [ 3, 3],
# [ 4, 4]],
#
# [[ 5, 5],
# [ 6, 6],
# [ 7, 7],
# [ 8, 8],
# [ 9, 9]],
#
# [[10, 10],
# [11, 11],
# [12, 12],
# [13, 13],
# [14, 14]],
#
# [[15, 15],
# [16, 16],
# [17, 17],
# [18, 18],
# [19, 19]]])
b[:,:,0] = 1 - b[:,:,1]
array([[[ 1, 0],
[ 0, 1],
[ -1, 2],
[ -2, 3],
[ -3, 4]],
[[ -4, 5],
[ -5, 6],
[ -6, 7],
[ -7, 8],
[ -8, 9]],
[[ -9, 10],
[-10, 11],
[-11, 12],
[-12, 13],
[-13, 14]],
[[-14, 15],
[-15, 16],
[-16, 17],
[-17, 18],
[-18, 19]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment