更新时间:2022-11-14 16:08:07
非常简单:
产生
l // 10 ** np.arange(10)[:, None] % 10
或者如果您想要一个适用的解决方案
Or if you want a solution that works for
你可以做
l = np.random.randint(0, 1000000, size=(3, 3, 3, 3))
l.shape
# (3, 3, 3, 3)
b = 10 # Base, in our case 10, for 1, 10, 100, 1000, ...
n = np.ceil(np.max(np.log(l) / np.log(b))).astype(int) # Number of digits
d = np.arange(n) # Divisor base b, b ** 2, b ** 3, ...
d.shape = d.shape + (1,) * (l.ndim) # Add dimensions to divisor for broadcasting
out = l // b ** d % b
out.shape
# (6, 3, 3, 3, 3)