1# tf.linalg.band_part(input, num_lower, num_upper, name=None)
2# num_lower is lower bound of number and num_upper is upper bound of number
3# we want to keep number for a matrix in a range num_lower to num upper and
4# if the number of matrix not fall at this range then this api makes it 0
5# Now this tensorflow api only do this work upper triangular region of matrix
6# and lower triangular region of this matrix
7# If the num_lower is less than num_upper then it applies for lower triangular matrix
8# and if num_lower is greater than num upper then it applies upper triangular of matrix
9
10
11# this example the api effect lower triangle of matrix ---
12input = np.array([[ 10, 1, 4, 3],
13 [1, 20, 1, 2],
14 [-2, 1, 30, 1],
15 [3, 10, 1, 40]])
16
17tf.linalg.band_part(
18 input, num_lower = 1, num_upper = 2, name=None
19)
20
21>><tf.Tensor: shape=(4, 4), dtype=int64, numpy=
22array([[10, 1, -4, 0],
23 [ 1, 20, 1, 2],
24 [ 0, 1, 30, 1],
25 [ 0, 0, 1, 40]])>
26
27# this example the api effect upper triangle of matrix ---
28input = np.array([[ 10, 1, 4, 3],
29 [1, 20, 1, 6],
30 [-2, 1, 30, 1],
31 [3, 10, 1, 40]])
32
33tf.linalg.band_part(
34 input, num_lower = 2, num_upper = 1, name=None
35)
36
37>><tf.Tensor: shape=(4, 4), dtype=int64, numpy=
38array([[10, 1, 0, 0],
39 [ 1, 20, 1, 0],
40 [-2, 1, 30, 1],
41 [ 0, 10, 1, 40]])>