栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python中 numpy f.view(‘f8,f8,f8,f8‘)函数说明

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python中 numpy f.view(‘f8,f8,f8,f8‘)函数说明

首先,view函数参数里“f8”表示float64的数据类型。numpy常用数据类型及类型代码

sort函数

numpy.sort(a, axis=-1, kind=None, order=None)

>>> a = np.array([[1,4],[3,1]])
>>> np.sort(a)                # 无axis参数默认最后一维排序
array([[1, 4],
       [1, 3]])
>>> np.sort(a, axis=None)     # axis为None则展开排序
array([1, 1, 3, 4])
>>> np.sort(a, axis=0)        # 在 axis维上排序
array([[1, 1],
       [3, 4]])
import numpy as np

A=np.array([[1,2,3,4],
            [1,2,3,4],
            [0,0,0,0],
            [11,22,33,44]])
print('A:',A)

B=np.array([[2,2,0,3],
            [9,9,9,9],
            [0,0,0,0],
            [11,22,33,44]])

rgb_set = set([tuple(x) for x in A])  #set不重复,唯一性
print("rgb_set:",rgb_set)
flow_set = set([tuple(x) for x in B])

print("*"*100)

fuse_temp = np.array([x for x in rgb_set | flow_set])  # Gather RGB proposals and FLOW proposals together
print(fuse_temp)

print("*"*100)
print(fuse_temp.view('i8,i8,i8,i8'))   #i8 f8都表示numpy数据格式,看第开头链接
print("*"*100)
print(np.sort(fuse_temp.view('i8,i8,i8,i8'), order=['f0'], axis=0))# 按第0列排序
print(np.sort(fuse_temp.view('i8,i8,i8,i8'), order=['f2'], axis=0))#按第二列排序
print("*"*100)
fuse_temp = np.sort(fuse_temp.view('i8,i8,i8,i8'), order=['f1'], axis=0).view(np.int)
print(fuse_temp)
print(fuse_temp[::-1])  #反向 倒着取一遍
A: [[ 1  2  3  4]
 [ 1  2  3  4]
 [ 0  0  0  0]
 [11 22 33 44]]
rgb_set: {(11, 22, 33, 44), (0, 0, 0, 0), (1, 2, 3, 4)}
****************************************************************************************************
[[11 22 33 44]
 [ 0  0  0  0]
 [ 2  2  0  3]
 [ 1  2  3  4]
 [ 9  9  9  9]]
****************************************************************************************************
[[(11, 22, 33, 44)]
 [( 0,  0,  0,  0)]
 [( 2,  2,  0,  3)]
 [( 1,  2,  3,  4)]
 [( 9,  9,  9,  9)]]
****************************************************************************************************
[[( 0,  0,  0,  0)]
 [( 1,  2,  3,  4)]
 [( 2,  2,  0,  3)]
 [( 9,  9,  9,  9)]
 [(11, 22, 33, 44)]]
[[( 0,  0,  0,  0)]
 [( 2,  2,  0,  3)]
 [( 1,  2,  3,  4)]
 [( 9,  9,  9,  9)]
 [(11, 22, 33, 44)]]
****************************************************************************************************
[[ 0  0  0  0]
 [ 1  2  3  4]
 [ 2  2  0  3]
 [ 9  9  9  9]
 [11 22 33 44]]
[[11 22 33 44]
 [ 9  9  9  9]
 [ 2  2  0  3]
 [ 1  2  3  4]
 [ 0  0  0  0]]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1030905.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号