Поиск в Интернете, который я нашел
https://github.com/vicariousinc/schema-games/blob/master/schema_games/utils.py
def shape_to_nzis(shape):
"""
Convert a shape tuple (int, int) to NZIs.
"""
return np.array(zip(*np.ones(shape).nonzero()))
In [48]: np.array(zip(*np.ones((3,4)).nonzero()))
Out[48]: array(<zip object at 0x7f39a009afc8>, dtype=object)
In [49]: len(_)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-49-556fcc1c5d2a> in <module>
----> 1 len(_)
TypeError: len() of unsized object
В py3 эту функцию необходимо использовать:
In [50]: np.array(list(zip(*np.ones((3,4)).nonzero())))
Out[50]:
array([[0, 0],
[0, 1],
[0, 2],
[0, 3],
[1, 0],
[1, 1],
[1, 2],
[1, 3],
[2, 0],
[2, 1],
[2, 2],
[2, 3]])