w3resource

NumPy: Create an array which looks like below array

NumPy: Array Object Exercise-47 with Solution

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

Sample Solution:-

Python Code:

import numpy as np
x = np.tri(4, 3, -1)
print(x)

Sample Output:

[[ 0.  0.  0.]                                                         
 [ 1.  0.  0.]                                                         
 [ 1.  1.  0.]                                                         
 [ 1.  1.  1.]]

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a 1-D array of 20 element spaced evenly on a log scale between 2. and 5., exclusive.
Next: Write a NumPy program to create an array which looks like below array.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}