numpy: weight to the repetitive array

  First import file module

import numpy as np

1, an array of deduplication

np.array = arr ([ " flowers " , " red " , " Betty " , " little cute " , " little darling " , " small motor " , " Xiaohua " , " Xiao Ming " , " Romantic Swordsman " , " little darling " , " scooter " ])

  Create an array

arr = np.unique(arr)

  Use unique () method to the array weight, and contains the sort function, you can sort of numbers, letters, do not support the sort of Chinese

2, an array of repeating

arr = np.arange(9).reshape((3, 3))

  Create a two-dimensional array

res = np.tile(arr,2)
res = np.tile(arr,[3,2])
res = np.tile(arr,[2,3,2])

  Use the tile () method, if the transmission parameter is a number, the default repeated along the column direction, if the transmission parameter is an array, it represents the repetition of each dimension

res = np.repeat(arr, 2, axis=1)
res = np.repeat(arr, 2, axis=0)

  Use repeat () method, the object is repeated entire row or entire column, parameter 1 : duplicate object, parameter 2 : the number of repetitions, parameter 3 : repeat dimension

Guess you like

Origin www.cnblogs.com/xmcwm/p/11834834.html