w3resource logo
Python Exercises

Python NumPy: Create an array which looks like below array

Python NumPy: Array Object Exercise-48 with Solution

Write a Python program to create an array which looks like below array.

Sample Solution:-

Python Code:

import numpy as np
x = np.triu(np.arange(2, 14).reshape(4, 3), -1)
print(x)

Sample Output:

[[ 2  3  4]                                                            
 [ 5  6  7]                                                            
 [ 0  9 10]                                                            
 [ 0  0 13]]

Python Code Editor:

import numpy as np
x = np.triu(np.arange(2, 14).reshape(4, 3), -1)
print(x)

Improve this sample solution and post your code through Disqus