使用 Numpy 参数化数组

H S*_*ora 1 python numpy machine-learning

如何定义 numpy 数组, X = numpy.array([x , x*x , x*x*x ,... ] 使得x=2 时输出为[2,4,8,..],其中x是 python 中的局部变量。

Mat*_*haq 6

三角形!:D

>>> 2**np.arange(30)

array([        1,         2,         4,         8,        16,        32,
              64,       128,       256,       512,      1024,      2048,
            4096,      8192,     16384,     32768,     65536,    131072,
          262144,    524288,   1048576,   2097152,   4194304,   8388608,
        16777216,  33554432,  67108864, 134217728, 268435456, 536870912])
Run Code Online (Sandbox Code Playgroud)