Python中asarray用法
来源:互联网 发布:安知玉如意江云儿 编辑:程序博客网 时间:2024/06/05 08:34
通过在编译环境中输入
import numpyhelp(numpy.asarray)
Help on function asarray in module numpy.core.numeric:
asarray(a, dtype=None, order=None)
Convert the input to an array.
Parameters
----------
a : array_like
Input data, in any form that can be converted to an array. This
includes lists, lists of tuples, tuples, tuples of tuples, tuples
of lists and ndarrays.
dtype : data-type, optional
By default, the data-type is inferred from the input data.
order : {'C', 'F'}, optional
Whether to use row-major ('C') or column-major ('F' for FORTRAN)
memory representation. Defaults to 'C'.
举例:
Convert a list into an array:将列表转换为数组
>>> a = [1,2]>>> numpy.asarray(a)array([1, 2])
将数据类型转换为float和int
>>> a= [1,2]>>> numpy.asarray(a,'f')array([ 1., 2.], dtype=float32)>>> numpy.asarray(a,'i')array([1, 2])
判断a中数是否大于0,如果大于0,则将该数置为1,
>>> a = [[1,2],[1,0]]>>> a = numpy.asarray(a) #必须先转换为array,否则出现array(1.0, dtype=float32)>>> numpy.asarray(a>0,'i') #'i'表示为dtype类型为intarray([[1, 1], [1, 0]])>>> numpy.asarray(a>0,'f')array([[ 1., 1.], [ 1., 0.]], dtype=float32)
1 0
- Python中asarray用法
- Python中numpy中asarray
- Python中numpy中asarray
- python中的numpy库的numpy.asarray
- numpy中array和asarray的区别
- python中enumerate用法
- Python中enumerate用法
- python 中strftime用法
- Python中flatten用法
- python 中 struct 用法
- python中yield用法
- python中”\“的用法
- python中yield用法
- Python 中 property 用法
- python中xrange用法
- Python中dict用法
- python中yield用法
- Python中flatten用法
- opencv filter2D
- Linux Redhat 6.4 Redis 2.6.14 缓存服务 完全安装手册
- OpenGL(3)GLUT库回调函数API
- SSL证书与Https应用部署小结
- wince下添加和删除驱动出现错误
- Python中asarray用法
- Struct和Class的区别
- 抽象工厂模式
- K-Means算法
- css兼容问题集锦
- Servlet的自我理解之6:ID会话跟踪技术的实现
- Android中的尺寸单位
- 创新,有时是不经意间开放的花朵——访2013 CCF青年科学家奖获得者朱军
- PAT1002题解