python help()函数(查看特定模块、关键词、函数等用法)
生活随笔
收集整理的這篇文章主要介紹了
python help()函数(查看特定模块、关键词、函数等用法)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
示例1:
import torch help(torch.ones)運行結果:
D:\Dontla_miniconda3.8\python.exe C:/Users/Administrator/Desktop/d2l/torch_code/code/test3.py Help on built-in function ones:ones(...)ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> TensorReturns a tensor filled with the scalar value `1`, with the shape definedby the variable argument :attr:`size`.Args:size (int...): a sequence of integers defining the shape of the output tensor.Can be a variable number of arguments or a collection like a list or tuple.Keyword arguments:out (Tensor, optional): the output tensor.dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.Default: if ``None``, uses a global default (see :func:`torch.set_default_tensor_type`).layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.Default: ``torch.strided``.device (:class:`torch.device`, optional): the desired device of returned tensor.Default: if ``None``, uses the current device for the default tensor type(see :func:`torch.set_default_tensor_type`). :attr:`device` will be the CPUfor CPU tensor types and the current CUDA device for CUDA tensor types.requires_grad (bool, optional): If autograd should record operations on thereturned tensor. Default: ``False``.Example::>>> torch.ones(2, 3)tensor([[ 1., 1., 1.],[ 1., 1., 1.]])>>> torch.ones(5)tensor([ 1., 1., 1., 1., 1.])進程已結束,退出代碼0示例2:
help(int) D:\Dontla_miniconda3.8\python.exe C:/Users/Administrator/Desktop/d2l/torch_code/code/test3.py Help on class int in module builtins:class int(object)| int([x]) -> integer| int(x, base=10) -> integer| | Convert a number or string to an integer, or return 0 if no arguments| are given. If x is a number, return x.__int__(). For floating point| numbers, this truncates towards zero.| | If x is not a number or if base is given, then x must be a string,| bytes, or bytearray instance representing an integer literal in the| given base. The literal can be preceded by '+' or '-' and be surrounded| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.| Base 0 means to interpret the base from the string as an integer literal.| >>> int('0b100', base=0)| 4| | Built-in subclasses:| bool| | Methods defined here:| | __abs__(self, /)| abs(self)| | __add__(self, value, /)| Return self+value.| | __and__(self, value, /)| Return self&value.| | __bool__(self, /)| self != 0| | __ceil__(...)| Ceiling of an Integral returns itself.| | __divmod__(self, value, /)| Return divmod(self, value).| | __eq__(self, value, /)| Return self==value.| | __float__(self, /)| float(self)| | __floor__(...)| Flooring an Integral returns itself.| | __floordiv__(self, value, /)| Return self//value.| | __format__(self, format_spec, /)| Default object formatter.| | __ge__(self, value, /)| Return self>=value.| | __getattribute__(self, name, /)| Return getattr(self, name).| | __getnewargs__(self, /)| | __gt__(self, value, /)| Return self>value.| | __hash__(self, /)| Return hash(self).| | __index__(self, /)| Return self converted to an integer, if self is suitable for use as an index into a list.| | __int__(self, /)| int(self)| | __invert__(self, /)| ~self| | __le__(self, value, /)| Return self<=value.| | __lshift__(self, value, /)| Return self<<value.| | __lt__(self, value, /)| Return self<value.| | __mod__(self, value, /)| Return self%value.| | __mul__(self, value, /)| Return self*value.| | __ne__(self, value, /)| Return self!=value.| | __neg__(self, /)| -self| | __or__(self, value, /)| Return self|value.| | __pos__(self, /)| +self| | __pow__(self, value, mod=None, /)| Return pow(self, value, mod).| | __radd__(self, value, /)| Return value+self.| | __rand__(self, value, /)| Return value&self.| | __rdivmod__(self, value, /)| Return divmod(value, self).| | __repr__(self, /)| Return repr(self).| | __rfloordiv__(self, value, /)| Return value//self.| | __rlshift__(self, value, /)| Return value<<self.| | __rmod__(self, value, /)| Return value%self.| | __rmul__(self, value, /)| Return value*self.| | __ror__(self, value, /)| Return value|self.| | __round__(...)| Rounding an Integral returns itself.| Rounding with an ndigits argument also returns an integer.| | __rpow__(self, value, mod=None, /)| Return pow(value, self, mod).| | __rrshift__(self, value, /)| Return value>>self.| | __rshift__(self, value, /)| Return self>>value.| | __rsub__(self, value, /)| Return value-self.| | __rtruediv__(self, value, /)| Return value/self.| | __rxor__(self, value, /)| Return value^self.| | __sizeof__(self, /)| Returns size in memory, in bytes.| | __sub__(self, value, /)| Return self-value.| | __truediv__(self, value, /)| Return self/value.| | __trunc__(...)| Truncating an Integral returns itself.| | __xor__(self, value, /)| Return self^value.| | as_integer_ratio(self, /)| Return integer ratio.| | Return a pair of integers, whose ratio is exactly equal to the original int| and with a positive denominator.| | >>> (10).as_integer_ratio()| (10, 1)| >>> (-10).as_integer_ratio()| (-10, 1)| >>> (0).as_integer_ratio()| (0, 1)| | bit_length(self, /)| Number of bits necessary to represent self in binary.| | >>> bin(37)| '0b100101'| >>> (37).bit_length()| 6| | conjugate(...)| Returns self, the complex conjugate of any int.| | to_bytes(self, /, length, byteorder, *, signed=False)| Return an array of bytes representing an integer.| | length| Length of bytes object to use. An OverflowError is raised if the| integer is not representable with the given number of bytes.| byteorder| The byte order used to represent the integer. If byteorder is 'big',| the most significant byte is at the beginning of the byte array. If| byteorder is 'little', the most significant byte is at the end of the| byte array. To request the native byte order of the host system, use| `sys.byteorder' as the byte order value.| signed| Determines whether two's complement is used to represent the integer.| If signed is False and a negative integer is given, an OverflowError| is raised.| | ----------------------------------------------------------------------| Class methods defined here:| | from_bytes(bytes, byteorder, *, signed=False) from builtins.type| Return the integer represented by the given array of bytes.| | bytes| Holds the array of bytes to convert. The argument must either| support the buffer protocol or be an iterable object producing bytes.| Bytes and bytearray are examples of built-in objects that support the| buffer protocol.| byteorder| The byte order used to represent the integer. If byteorder is 'big',| the most significant byte is at the beginning of the byte array. If| byteorder is 'little', the most significant byte is at the end of the| byte array. To request the native byte order of the host system, use| `sys.byteorder' as the byte order value.| signed| Indicates whether two's complement is used to represent the integer.| | ----------------------------------------------------------------------| Static methods defined here:| | __new__(*args, **kwargs) from builtins.type| Create and return a new object. See help(type) for accurate signature.| | ----------------------------------------------------------------------| Data descriptors defined here:| | denominator| the denominator of a rational number in lowest terms| | imag| the imaginary part of a complex number| | numerator| the numerator of a rational number in lowest terms| | real| the real part of a complex number進程已結束,退出代碼0總結
以上是生活随笔為你收集整理的python help()函数(查看特定模块、关键词、函数等用法)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python matplotlib py
- 下一篇: pytorch torch.detach