|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近学习人工智能,看到了玩具程序用到了binary = np.unpackbits(np.array([range(largest_number)], dtype=np.uint8).T, axis=1)这样的代码。
我想请教各位这里unpackbits的作用是什么呀。最好能举例说明下unpackbit的用法,万分感谢。
- >>> help(numpy.unpackbits)
- Help on built-in function unpackbits in module numpy.core.multiarray:
- unpackbits(...)
- 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
- Unpacks along this axis.
-
- 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, 0, 0, 0, 0, 0, 1, 0],
- [0, 0, 0, 0, 0, 1, 1, 1],
- [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)
复制代码
|
|