0

I have a function f(x):[0,1]-> Rⁿ such as:

>>> f(0.54)
array([0.2, 0.3, 4.0, 5.2, ... , 1.0])

How can I efficiently apply that to a vector, in order to generate a matrix?

Example:

>>> f([0.54, 0.32, 0.56, 0.21])
array([0.2, 0.3, 4.0, 5.2, ... , 1.0],
      [0.6, 0.1, 0.0, 2.3, ... , 4.7],
      [0.1, 7.1, 0.2, 4.9, ... , 3.1],
      [1.3, 2.8, 1.2, 1.1, ... , 5.3])

Note: numpy solutions are very welcome :)

Pedro
  • 1,121
  • 7
  • 16
  • The issue is not about mapping, but on doing the multidimensional mapping in a efficient way. – Pedro Nov 26 '17 at 01:42
  • As long as the function is black box there isn't much you can do. A one to many mapping complicates the task. Vectorize takes signature, but is slower. frompyfunc is my favorite. It returns an object. The resulting array will need stacking,. – hpaulj Nov 26 '17 at 03:24
  • 1
    I added a link to 'vectorize' question with a one-to-many function. – hpaulj Nov 26 '17 at 03:50

0 Answers0