加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

numpy.unpackbits()

发布时间:2020-12-14 05:15:09 所属栏目:大数据 来源:网络整理
导读:numpy.unpackbits numpy. unpackbits ( myarray ,? axis=None ) Unpacks elements of a uint8 array into a binary-valued output array. Each element of? myarray ?represents a bit-field that should be unpacked into a binary-valued output array. Th

numpy.unpackbits

numpy. unpackbits (myarray,?axis=None)

Unpacks elements of a uint8 array into a binary-valued output array.

Each element of?myarray?represents a bit-field that should be unpacked into a binary-valued output array. The shape of the output array is either 1-D (if?axis?is None) or the same shape as the input array with unpacking done along the axis specified.

Parameters:
myarray? :?ndarray,uint8 type

Input array.

axis? :?int,optional

The dimension over which bit-unpacking is done.?None?implies unpacking the flattened array.

Returns:
unpacked? :?ndarray,uint8 type

The elements are binary-valued (0 or 1).

See also

packbits
Packs the elements of a binary-valued array into bits in a uint8 array.

Examples

>>>
>>> a = np.array([[2],[7],[23]],dtype=np.uint8) >>> a array([[ 2], [ 7], [23]],dtype=uint8) >>> b = np.unpackbits(a,axis=1) >>> b array([[0,1,0], [0,1],1]],dtype=uint8)



import numpy as nplargest_number = 10 print(range(largest_number))for i in range(largest_number): print(i)print(range,‘range‘) print(np.array([range(largest_number)],dtype=np.uint8),‘np.array([range(largest_number)],dtype=np.uint8)‘)print(np.array([range(largest_number)],dtype=np.uint8).T,dtype=np.uint8).T‘) binary = np.unpackbits( np.array([range(largest_number)],axis=1)print(binary[0]) binary = np.unpackbits( np.array([range(largest_number)],axis=1)print(binary[0])print(binary) ‘‘‘range(0,10)0123456789<class ‘range‘> range[[0 1 2 3 4 5 6 7 8 9]] np.array([range(largest_number)],dtype=np.uint8)[[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]] np.array([range(largest_number)],dtype=np.uint8).T[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1][0 0 0 0 0 0 0 0][[0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0] [0 0 0 0 0 0 1 1] [0 0 0 0 0 1 0 0] [0 0 0 0 0 1 0 1] [0 0 0 0 0 1 1 0] [0 0 0 0 0 1 1 1] [0 0 0 0 1 0 0 0] [0 0 0 0 1 0 0 1]]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读