美文网首页我爱编程
python-numpy之tile函数

python-numpy之tile函数

作者: 五秋木 | 来源:发表于2018-04-06 20:57 被阅读0次

    在机器学习算法KNN讲解中出现np.tile(A,B),其中A为array,B为tuple,例如:(3,2)
    具体使用如下:

    import numpy as np
    A=np.array([0,0])
    np.tile([0,0],5)#在列方向上重复[0,0]5次,默认行1次,等价于np.tile(A,5)
    #array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    np.tile(A,(1,1))#在列方向上重复[0,0]1次,行1次  
    array([[0, 0]])  
    np.tile([0,0],(2,1))#在列方向上重复[0,0]1次,行2次  
    array([[0, 0],  
           [0, 0]])  
    np.tile([0,0],(1,3))#在列方向上重复[0,0]3次,行1次  
    array([[0, 0, 0, 0, 0, 0]])
    

    相关文章

      网友评论

        本文标题:python-numpy之tile函数

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