数组的重复和去重

一、重复

import numpy as np

# 创建一个数组
# arr = np.array([1,2,3,3,2,1,12,3,4,5,6])
arr = np.arange(4).reshape((2, 2))

# 重复数据 tile作为整体进行重复N次
# res = np.tile(arr,2)
# print(res)

# 按列进行重复N次
# res = np.repeat(arr,2,axis=1)
res = np.repeat(arr, 2, axis=0)
print(res)

二、去重

import numpy as np

# 创建一个数组
arr = np.array([1,2,3,3,2,1,12,3,4,5,6])

# 对数组进行去重
# unique  去重+ 排序 (仅支持英文与数字)
res = np.unique(arr)
print(res)

猜你喜欢

转载自blog.csdn.net/qq_40576301/article/details/101391062