import numpy as np

a = np.arange(16).reshape(4, 4)
print(a)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]
#  [12 13 14 15]]

print(np.tril(a))
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

print(np.tril(a, k=2))
# [[ 0  1  2  0]
#  [ 4  5  6  7]
#  [ 8  9 10 11]
#  [12 13 14 15]]

print(np.tril(a, k=-1))
# [[ 0  0  0  0]
#  [ 4  0  0  0]
#  [ 8  9  0  0]
#  [12 13 14  0]]

a = np.arange(12).reshape(3, 4)
print(a)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(np.tril(a))
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]]

print(np.tril(a, k=-1))
# [[0 0 0 0]
#  [4 0 0 0]
#  [8 9 0 0]]

print(np.tril(np.arange(32).reshape(2, 4, 4)))
# [[[ 0  0  0  0]
#   [ 4  5  0  0]
#   [ 8  9 10  0]
#   [12 13 14 15]]
# 
#  [[16  0  0  0]
#   [20 21  0  0]
#   [24 25 26  0]
#   [28 29 30 31]]]

print(np.tril(np.arange(16).reshape(1, 1, 4, 4)))
# [[[[ 0  0  0  0]
#    [ 4  5  0  0]
#    [ 8  9 10  0]
#    [12 13 14 15]]]]

a_tril = np.tril(np.arange(16).reshape(4, 4))
print(a_tril)
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

print(a_tril.T)
# [[ 0  4  8 12]
#  [ 0  5  9 13]
#  [ 0  0 10 14]
#  [ 0  0  0 15]]

print(a_tril.T.T)
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

import numpy as np

a = np.arange(16).reshape(4, 4)
print(a)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]
#  [12 13 14 15]]

print(np.tril(a))
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

print(np.tril(a, k=2))
# [[ 0  1  2  0]
#  [ 4  5  6  7]
#  [ 8  9 10 11]
#  [12 13 14 15]]

print(np.tril(a, k=-1))
# [[ 0  0  0  0]
#  [ 4  0  0  0]
#  [ 8  9  0  0]
#  [12 13 14  0]]

a = np.arange(12).reshape(3, 4)
print(a)
# [[ 0  1  2  3]
#  [ 4  5  6  7]
#  [ 8  9 10 11]]

print(np.tril(a))
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]]

print(np.tril(a, k=-1))
# [[0 0 0 0]
#  [4 0 0 0]
#  [8 9 0 0]]

print(np.tril(np.arange(32).reshape(2, 4, 4)))
# [[[ 0  0  0  0]
#   [ 4  5  0  0]
#   [ 8  9 10  0]
#   [12 13 14 15]]
# 
#  [[16  0  0  0]
#   [20 21  0  0]
#   [24 25 26  0]
#   [28 29 30 31]]]

print(np.tril(np.arange(16).reshape(1, 1, 4, 4)))
# [[[[ 0  0  0  0]
#    [ 4  5  0  0]
#    [ 8  9 10  0]
#    [12 13 14 15]]]]

a_tril = np.tril(np.arange(16).reshape(4, 4))
print(a_tril)
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

print(a_tril.T)
# [[ 0  4  8 12]
#  [ 0  5  9 13]
#  [ 0  0 10 14]
#  [ 0  0  0 15]]

print(a_tril.T.T)
# [[ 0  0  0  0]
#  [ 4  5  0  0]
#  [ 8  9 10  0]
#  [12 13 14 15]]

# [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11] #  [12 13 14 15]] # [[ 0  0  0  0] #  [ 4  5  0  0] #  [ 8  9 10  0] #  [12 13 14 15]] # [[ 0  1  2  0] #  [ 4  5  6  7] #  [ 8  9 10 11] #  [12 13 14 15]] # [[ 0  0  0  0] #  [ 4  0  0  0] #  [ 8  9  0  0] #  [12 13 14  0]] # [[ 0  1  2  3] #  [ 4  5  6  7] #  [ 8  9 10 11]] # [[ 0  0  0  0] #  [ 4  5  0  0] #  [ 8  9 10  0]] # [[0 0 0 0] #  [4 0 0 0] #  [8 9 0 0]] # [[[ 0  0  0  0] #   [ 4  5  0  0] #   [ 8  9 10  0] #   [12 13 14 15]] # #  [[16  0  0  0] #   [20 21  0  0] #   [24 25 26  0] #   [28 29 30 31]]] # [[[[ 0  0  0  0] #    [ 4  5  0  0] #    [ 8  9 10  0] #    [12 13 14 15]]]] # [[ 0  0  0  0] #  [ 4  5  0  0] #  [ 8  9 10  0] #  [12 13 14 15]] # [[ 0  4  8 12] #  [ 0  5  9 13] #  [ 0  0 10 14] #  [ 0  0  0 15]] # [[ 0  0  0  0] #  [ 4  5  0  0] #  [ 8  9 10  0] #  [12 13 14 15]]