map labmda 构造数组

import numpy as np

if __name__ == '__main__':
    zero = np.zeros((1, 3, 3))
    a = np.array([1, 2, 3]).reshape((1, 1, 3))
    b = np.ones((1, 1, 1))
    print(a)
    print(b)
    a, b = map(lambda x: x+zero, [a, b])
    print(a.shape)
    print(b.shape)
    print(a)
    print(b)
[[[1 2 3]]]
[[[1.]]]
(1, 3, 3)
(1, 3, 3)
[[[1. 2. 3.]
  [1. 2. 3.]
  [1. 2. 3.]]]
[[[1. 1. 1.]
  [1. 1. 1.]
  [1. 1. 1.]]]
import numpy as np

if __name__ == '__main__':
    zero = np.zeros((1, 3, 3))
    a = np.array([1, 2, 3]).reshape((1, 3, 1))
    b = np.ones((1, 1, 1))
    print(a)
    print(b)
    a, b = map(lambda x: x+zero, [a, b])
    print(a.shape)
    print(b.shape)
    print(a)
    print(b)
[[[1]
  [2]
  [3]]]
[[[1.]]]
(1, 3, 3)
(1, 3, 3)
[[[1. 1. 1.]
  [2. 2. 2.]
  [3. 3. 3.]]]
[[[1. 1. 1.]
  [1. 1. 1.]
  [1. 1. 1.]]]

理解:

文章目录