# numpy的argsort和sum和tile函数

In [40]:distances

Out[40]:array([ 1.48660687,  1.41421356,  0.        ,  0.1       ])

In [41]:distances.argsort()

Out[41]:array([2, 3, 1, 0])

axis决定了sum函数作用的轴值(维度)。

In [40]:np.sum([[1,2], [2, 3], [4,5]])

Out[40]: 17

In [41]:np.sum([[0, 1, 3], [3, 5, 8], [4, 5, 6]], axis=0)

Out[41]:array([ 7, 11, 17])

In [42]:np.sum([1, 2, 3,4 ,6], axis=0)

Out[42]: 16

In [33]:np.sum([[0, 1], [3, 5], [2, 5]], axis=1)

Out[33]:array([1, 8, 7])

tile(A, reps)

Construct an array by repeating A the number of times given by reps.

In [47]:tile([1, 2], 2)

Out[47]:array([1, 2, 1, 2])

In [48]:tile([1, 2], 1)

Out[48]:array([1, 2])

In [70]:tile([1, 2, 3], (1, 1))

Out[70]:array([[1, 2, 3]])

In [67]:tile([1, 2, 3], (1, 2))

Out[67]:array([[1, 2, 3, 1, 2, 3]])

In [69]:tile([1, 2, 3], (3, 2))

Out[69]:

array([[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]])

In [83]:tile([1, 2, 3], (4, 3, 2))

Out[83]:

array([[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]]])

2让元素元组[1, 2, 3]变成

[1, 2, 3, 1, 2, 3]，

3让[1, 2, 3, 1, 2, 3]变成

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]]，

3让

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]]，

[[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]],

[[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3],

[1, 2, 3, 1, 2, 3]]]

Top