Issue
I want to create this from multiple arrays, best using NumPy:
1 0 0 0 0 0
1 1 0 0 0 0
1 1 1 0 0 0
1 1 1 1 0 0
1 1 1 1 1 0
1 1 1 1 1 1
However, I prefer if a library is used to create this, how do I go about doing this?
Note: NumPy can be used to create the array as well.
There are a lot of answers on SO, but they all provide answers that do not use libraries, and I haven't been able to find anything online to produce this!
Solution
Using numpy.tri
Syntax:
numpy.tri(N, M=None, k=0, dtype=<class 'float'>, *, like=None)
Basically it creates an array with 1
's at and below the given diagonal and 0
's elsewhere.
Example:
import numpy as np
np.tri(6, dtype=int)
>>>
array([[1, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1]])
Answered By - DialFrost
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.