Numpy 过滤,排序,组合,重构

Numpy 过滤,排序,组合,重构

  • 过滤
  • 排序
  • 组合
  • 重构

过滤

获取大于105的值

vals = dataset[dataset>105]

使用extract,获取大于90,小于95的值

vals = np.extract((dataset > 90) & (dataset < 95), dataset)

where 方法针对匹配值获取索引(行,列)

rows, cols = np.where(abs(dataset-100) - 1)
indices = [[ rows[index], cols[index]] for (index, _) in np.ndenumerate(rows)]

Numpy 过滤,排序,组合,重构_第1张图片

排序

对每一行进行排序

row = np.sort(dataset)

对每一列进行排序

col = np.sort(dataset, axis=0)

argsort方法不改变原数据集

sorte = np.argsort(dataset)

组合

横向组合
在这里插入图片描述

col = np.vstack([halfed_frist[0], halfed_frist[1]])

在这里插入图片描述
竖向组合
在这里插入图片描述

secol = np.hstack([col, thirds[1]])

在这里插入图片描述

重构

重构为一维列表,如果值为-1,则Numpy会自己找出这个值

single = np.reshape(dataset, (1,-1))

重构为两列

two_col = dataset.reshape(-1,2)
two_col.shape

在这里插入图片描述

你可能感兴趣的:(Numpy,numpy,重构,python)