numpy.unique
Find the unique elements of an array.
Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique elements: the indices of the input array that give the unique values, the indices of the unique array that reconstruct the input array, and the number of times each unique value comes up in the input array.
>>> np.unique([1, 1, 2, 2, 3, 3])
array([1, 2, 3])
>>> a = np.array([[1, 1], [2, 3]])
>>> np.unique(a)
array([1, 2, 3])
>>> a = np.array([[1, 0, 0], [1, 0, 0], [2, 3, 4]])
>>> np.unique(a, axis=0)
array([[1, 0, 0], [2, 3, 4]])
>>> a = np.array(['a', 'b', 'b', 'c', 'a'])
>>> u, indices = np.unique(a, return_index=True)
>>> u
array(['a', 'b', 'c'],
dtype='|S1')
>>> indices
array([0, 1, 3])
>>> a[indices]
array(['a', 'b', 'c'],
dtype='|S1')
>>> a = np.array([1, 2, 6, 4, 2, 3, 2])
>>> u, indices = np.unique(a, return_inverse=True)
>>> u
array([1, 2, 3, 4, 6])
>>> indices
array([0, 1, 4, 3, 1, 2, 1])
>>> u[indices]
array([1, 2, 6, 4, 2, 3, 2])
numpy.unique的更多相关文章
- NumPy 学习笔记(三)
NumPy 数组操作: 1.修改数组形状 a.numpy.reshape(arr, newshape, order='C') 在不改变数据的条件下修改形状 b.numpy.ndarray.flat 是 ...
- Numpy学习笔记(二)
(1)NumPy - 切片和索引 l ndarray对象中的元素遵循基于零的索引. 有三种可用的索引方法类型: 字段访问,基本切片和高级索引. l 基本切片 Python 中基本切片概念到 n 维 ...
- Numpy 数组操作
Numpy 数组操作 Numpy 中包含了一些函数用于处理数组,大概可分为以下几类: 修改数组形状 翻转数组 修改数组维度 连接数组 分割数组 数组元素的添加与删除 修改数组形状 函数 描述 resh ...
- python数据分析Numpy(二)
Numpy (Numerical Python) 高性能科学计算和数据分析的基础包: ndarray,多维数组(矩阵),具有矢量运算能力,快速.节省空间: 矩阵运算,无需循环,可以完成类似Matlab ...
- python之numpy的基本使用
https://blog.csdn.net/cxmscb/article/details/54583415 一.numpy概述 numpy(Numerical Python)提供了python对多维数 ...
- Numpy 函数总结 (不断更新)
本篇主要收集一些平时见到的 Numpy 函数. numpy.random.seed & numpy.random.RandomState np.random.seed() 和 np.rando ...
- Python常用库之一:Numpy
Numpy支持大量的维度数组和矩阵运算,对数组运算提供了大量的数学函数库! Numpy比Python列表更具优势,其中一个优势便是速度.在对大型数组执行操作时,Numpy的速度比Python列表的速度 ...
- numpy利用数组进行数据处理
将条件逻辑表述为数组运算 numpy.where()是一个三目运算的表达式 In [34]: xarr = np.array([1.1,1.2,1.3,1.4,1.5]) In [35]: yarr ...
- Python Numpy Array
Numpy 是Python中数据科学中的核心组件,它给我们提供了多维度高性能数组对象. Arrays Numpy.array dtype 变量 dtype变量,用来存放数据类型, 创建数组时可以同 ...
随机推荐
- STM32中stm32f0xx_flash.icf文件的作用详解!(不错的!)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/weibo1230123/article/details/80142210 每个芯片开发商都会针对每款 ...
- windows下zookeeper单机版安装+dubbo-admin安装注意点
一:zookeeper安装 安转包下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper 复制修改conf下的zoo_sample.cfg为zoo.cf ...
- C# 私有字段前缀 _ 的设置(VS2019, .editorconfig)
常量和静态只读字段大写 私有字段前缀 _ #### Naming styles #### # Naming rules dotnet_naming_rule.const_should_be_all_u ...
- php round()函数 语法
php round()函数 语法 作用:round()函数的作用是对浮点数进行四舍五入 语法:round(X,prec) 参数: 参数 描述 X 要做处理的数字 prec 指定小数点后的位数 说明:返 ...
- 【2019 Multi-University Training Contest 4】
01:https://www.cnblogs.com/myx12345/p/11644076.html 02: 03:https://www.cnblogs.com/myx12345/p/116478 ...
- Shorten IPv6 Address
题目链接 题意:转换一个128位的二进制串,变成16进制,并且格式为x:x:x:x:x:x:x:x然后多个相邻的0变成::,且只有一个::,求变成的字典序最小且最短的字符串. 思路:大水题,但是就是一 ...
- bugku | flagphp
1.开脑洞 http://123.206.87.240:8002/flagphp/?hint=1 2.读源码得到条件是要求反序列化后的‘ISecer’的值等于$KEY <?php error_r ...
- [CSP-S模拟测试]:赤壁情(DP)
前赤壁赋 壬戌之秋,七月既望,苏子与客泛舟游于赤壁之下.清风徐来,水波不兴.举酒属客,诵明月之诗,歌窈窕之章.少焉,月出于东山之上,徘徊于斗牛之间.白露横江,水光接天.纵一苇之所如,凌万顷之茫然.浩浩 ...
- LocalActivityManager如何在一个Activity的一部分中显示其他Activity
首先要使用该方法,页面必须继承ActivityGroup. 总的来说,实现"如何在一个Activity的一部分中显示其他Activity"除了LocalActivityManage ...
- mysql联合查询sql优化
我们在使用mysql数据库时,经常会使用到mysql的联合查询,联合查询分为内连接和外连接,内连接查询结果是联合的表都存在匹配才会有结果,外连接则根据驱动表是否存在匹配来生成结果集. 这里使用mysq ...