【问题标题】:getting square and cube of numpy and appending it得到 numpy 的正方形和立方体并附加它
【发布时间】:2019-03-25 23:50:26
【问题描述】:

我有一个如下所示的 numpy 数组:-

array([[2],
       [3],
       [4],
       [5]])

我想对每个元素进行平方和立方,然后将其附加到 numpy. 我想要下面的输出

array([[2, 4, 8],
       [3, 9, 27],
       [4, 16, 64],
       [5, 25, 125]])

【问题讨论】:

    标签: python python-3.x python-2.7 numpy numpy-ndarray


    【解决方案1】:

    np.powernumpy broadcasting 属性一起使用-

    np.power(a, [1,2,3])
    
    #array([[  2,   4,   8],
    #       [  3,   9,  27],
    #       [  4,  16,  64],
    #       [  5,  25, 125]], dtype=int32)
    

    【讨论】:

    • 立方体是什么
    • 立方体包含在指数中。
    • 哦,是的,我很糟糕,我明白了,谢谢 :)
    猜你喜欢
    • 2020-02-08
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多