美文网首页Python
python numpy数组运算

python numpy数组运算

作者: SkTj | 来源:发表于2019-09-27 10:30 被阅读0次

    Python lists

    x = [1, 2, 3, 4]
    y = [5, 6, 7, 8]
    x * 2
    [1, 2, 3, 4, 1, 2, 3, 4]
    x + 10
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: can only concatenate list (not "int") to list
    x + y
    [1, 2, 3, 4, 5, 6, 7, 8]

    Numpy arrays

    import numpy as np
    ax = np.array([1, 2, 3, 4])
    ay = np.array([5, 6, 7, 8])
    ax * 2
    array([2, 4, 6, 8])
    ax + 10
    array([11, 12, 13, 14])
    ax + ay
    array([ 6, 8, 10, 12])
    ax * ay
    array([ 5, 12, 21, 32])

    相关文章

      网友评论

        本文标题:python numpy数组运算

        本文链接:https://www.haomeiwen.com/subject/rndguctx.html