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]]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值