Course 5 Week 4 tf.linalg.band_part

I was going through the documentation of tf.linalg.band_part from tf.linalg.band_part  |  TensorFlow Core v2.5.0 but I did not understand how the output is calculated for the following examples
if ‘input’ is [[ 0, 1, 2, 3]
[-1, 0, 1, 2]
[-2, -1, 0, 1]
[-3, -2, -1, 0]],

tf.linalg.band_part(input, 1, -1) ==> [[ 0, 1, 2, 3]
[-1, 0, 1, 2]
[ 0, -1, 0, 1]
[ 0, 0, -1, 0]],

tf.linalg.band_part(input, 2, 1) ==> [[ 0, 1, 0, 0]
[-1, 0, 1, 0]
[-2, -1, 0, 1]
[ 0, -2, -1, 0]]

Please help.

The function is to keep input data around central band, and remove (set to 0) others. The function parameter num_lower is the number of lower bands to keep, num_upper is the number of upper bands to keep (-1 means keep all, 0 means remove all). Regarding lower/upper bands, see bellow:
image

1 Like