创建数组
创建数组
np.array(object,dtype=None,copy=True,order=None,subok=False,ndmin=0)
object |
表示一个数组序列(可以是列表/元组/...) |
dtype |
可选参数,通过它可以更改数组的数据类型 |
copy |
可选参数,表示数组能否被复制,默认是True |
ndmin |
用于指定数组的维度 |
subok |
可选参数,类型为bool值,默认False |
arange创建区间数组
np.arange(start,stop,step,dtype)
start |
起始值,默认为0 |
stop |
终止值(不包含) |
step |
步长,默认为1 |
dtype |
返回ndarray数据类型 |
创建浮点型数组
返回指定类型的数组
步长创建数组
数据多
linspace()创建等差数列
返回在间隔 [开始,停止] 上计算的num个均匀间隔的样本。,数组是一个等差数列
np.linspace(start,stop,num=50,endpoint=True,retstep=False,dtype=None)
start |
必填项,序列的起始值 |
stop |
必填项,序列的终止值,如果endpoint为true,该值包含于数列中 |
num |
要生成的等步长的样本数量,默认为50 |
endpoint |
该值为true时,数列中包含stop值,反之不包含,默认是True |
retstep |
如果为true,生成的数组中会显示间距,反之不显示 |
dtype |
ndarray的数据类型 |
logspace()创建等比数列
返回在间隔 [开始,停止]上计算的num个均匀间隔的样本。数组是一个等比数列
np.logspace(start,stop,num=50,endpoint=True,base=10.0,dtype=None)
start |
必填项,序列的起始值 |
stop |
必填项,序列的终止值,如果endpoint为true,该值包含于数列中 |
num |
要生成的等步长的样本数量,默认为50 |
endpoint |
该值为true时,数列中包含stop的值,反之不包含,默认为true |
base |
对数log的底数 |
dtype |
ndarray的数据类型 |
查看传入类型
type()
查看传入的数据类型
dtype
import numpy as np
# array传入列表
t1 = np.array([1,2,3])
print(t1)
print(type(t1))
# array传入范围
t2 = np.array(range(10))
print(t2)
print(type(t2))
print(t2.dtype)
# arange相对于传入范围,参数与range用法一致
t3 = np.arange(10)
print(t3)
print(type(t3))
print(t3.dtype)
numpy中常见的更多数据类型
指定创建的数组的数据类型
dt