pce*_*con 3 python arrays numpy sequence
我想创建一个如下所示的数组:
# 0 | 4 | 8 | 16 | 32
Run Code Online (Sandbox Code Playgroud)
其中,除第一个之外的每个元素是前一个元素的两倍.我可以通过迭代创建这个更小的东西,依此类推.
但是,由于Python提供了许多单线函数,我想知道是否有一个允许我这样做.
可能是一行,但这更明确:
x = np.multiply.accumulate( np.ones( 10 )*2)
x[0] = 0
Run Code Online (Sandbox Code Playgroud)
要么
x = 2**np.arange(1,10)
x[0] = 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |