xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.32k stars 394 forks source link

numpy.fromfunction equivalent #2558

Open james-mxr opened 2 years ago

james-mxr commented 2 years ago

Example;

import numpy as np
np.fromfunction(lambda i, j: i == j, (2, 3), dtype=int)

Would be nice to have an inbuilt equivalent.

tdegeus commented 2 years ago

Do I understand that it is a wrapper around meshgrid and https://xtensor.readthedocs.io/en/latest/operator.html#universal-functions-and-vectorization ? If so, the wrapper should be easy to implement. Would you be willing to give it a shot?