The core function for the np.tri...
family of functions is np.tri
.
Looking at its code, we see that it does (for a square array):
In [36]: np.greater_equal.outer(np.arange(4),np.arange(+1, 4+1))
Out[36]:
array([[False, False, False, False],
[ True, False, False, False],
[ True, True, False, False],
[ True, True, True, False]])
Playing around with that I can generate something closer to your example:
In [39]: np.greater_equal.outer(np.arange(4),.5*np.arange(+1, 8+1))
Out[39]:
array([[False, False, False, False, False, False, False, False],
[ True, True, False, False, False, False, False, False],
[ True, True, True, True, False, False, False, False],
[ True, True, True, True, True, True, False, False]])
In [40]: _.astype(int)
Out[40]:
array([[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 0, 0]])
Whether this is a useful approach depends on how general of a triangle you want. The example is a variation on the traditional lower triangle. But if the points were more general, say:
(1,1), (3,2), (2,6)
you'd have to come up with a more sophisticated