How to apply function which returns vector to each numpy array element (and get array with higher dimension)

前端 未结 3 804
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 12:19

Let\'s write it directly in code

Note: I edited mapper (original example use x -> (x, 2 * x, 3 * x) just for example), to generic blackbox function, which cause the trou

3条回答
  •  悲&欢浪女
    2021-01-25 13:25

    I might be getting this wrong, but comprehension does the job:

    a = np.array([[0, 1],
         [2, 3]])
    
    
    np.array([[[j, j*2, j*3] for j in i] for i in a ])
    #[[[0 0 0]
    #  [1 2 3]]
    #
    # [[2 4 6]
    #  [3 6 9]]]
    

提交回复
热议问题