Home > AI > Language > Python >

(interview) Functional Arrays

## Functional Arrays

Create a function that takes a lambda, a dimensions shape and the Numpy dtype, and produces an array.

```py
import numpy as np

def create_array_from_function(f, d, dtype=None):
    pass

print(create_array_from_function(lambda i,j: (i - j)**2, [4, 4]))
# [[0. 1. 4. 9.]
#  [1. 0. 1. 4.]
#  [4. 1. 0. 1.]
#  [9. 4. 1. 0.]]
```

Leave a Reply