鱼C论坛

 找回密码
 立即注册
查看: 1599|回复: 5

[已解决]求大神帮助,本人小白一枚。

[复制链接]
发表于 2017-12-6 18:37:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
最近学习人工智能,看到了玩具程序用到了binary = np.unpackbits(np.array([range(largest_number)], dtype=np.uint8).T, axis=1)这样的代码。
我想请教各位这里unpackbits的作用是什么呀。最好能举例说明下unpackbit的用法,万分感谢。
最佳答案
2017-12-6 19:49:19
  1. >>> help(numpy.unpackbits)
  2. Help on built-in function unpackbits in module numpy.core.multiarray:

  3. unpackbits(...)
  4.     unpackbits(myarray, axis=None)
  5.    
  6.     Unpacks elements of a uint8 array into a binary-valued output array.
  7.    
  8.     Each element of `myarray` represents a bit-field that should be unpacked
  9.     into a binary-valued output array. The shape of the output array is either
  10.     1-D (if `axis` is None) or the same shape as the input array with unpacking
  11.     done along the axis specified.
  12.    
  13.     Parameters
  14.     ----------
  15.     myarray : ndarray, uint8 type
  16.        Input array.
  17.     axis : int, optional
  18.        Unpacks along this axis.
  19.    
  20.     Returns
  21.     -------
  22.     unpacked : ndarray, uint8 type
  23.        The elements are binary-valued (0 or 1).
  24.    
  25.     See Also
  26.     --------
  27.     packbits : Packs the elements of a binary-valued array into bits in a uint8
  28.                array.
  29.    
  30.     Examples
  31.     --------
  32.     >>> a = np.array([[2], [7], [23]], dtype=np.uint8)
  33.     >>> a
  34.     array([[ 2],
  35.            [ 7],
  36.            [23]], dtype=uint8)
  37.     >>> b = np.unpackbits(a, axis=1)
  38.     >>> b
  39.     array([[0, 0, 0, 0, 0, 0, 1, 0],
  40.            [0, 0, 0, 0, 0, 1, 1, 1],
  41.            [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-6 18:59:33 | 显示全部楼层
都开始玩ai了啊 不会哦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-6 19:25:30 | 显示全部楼层
我刚刚入门,ai很牛逼的样子
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-6 19:49:19 | 显示全部楼层    本楼为最佳答案   
  1. >>> help(numpy.unpackbits)
  2. Help on built-in function unpackbits in module numpy.core.multiarray:

  3. unpackbits(...)
  4.     unpackbits(myarray, axis=None)
  5.    
  6.     Unpacks elements of a uint8 array into a binary-valued output array.
  7.    
  8.     Each element of `myarray` represents a bit-field that should be unpacked
  9.     into a binary-valued output array. The shape of the output array is either
  10.     1-D (if `axis` is None) or the same shape as the input array with unpacking
  11.     done along the axis specified.
  12.    
  13.     Parameters
  14.     ----------
  15.     myarray : ndarray, uint8 type
  16.        Input array.
  17.     axis : int, optional
  18.        Unpacks along this axis.
  19.    
  20.     Returns
  21.     -------
  22.     unpacked : ndarray, uint8 type
  23.        The elements are binary-valued (0 or 1).
  24.    
  25.     See Also
  26.     --------
  27.     packbits : Packs the elements of a binary-valued array into bits in a uint8
  28.                array.
  29.    
  30.     Examples
  31.     --------
  32.     >>> a = np.array([[2], [7], [23]], dtype=np.uint8)
  33.     >>> a
  34.     array([[ 2],
  35.            [ 7],
  36.            [23]], dtype=uint8)
  37.     >>> b = np.unpackbits(a, axis=1)
  38.     >>> b
  39.     array([[0, 0, 0, 0, 0, 0, 1, 0],
  40.            [0, 0, 0, 0, 0, 1, 1, 1],
  41.            [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2017-12-7 16:21:18 | 显示全部楼层
楼上大牛,支持
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-7 21:12:29 | 显示全部楼层
感谢,忘了help啦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-18 08:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表