import numpy as np
a = np.dtype(int)
print(a.type)# <class 'numpy.int32'>
print(a.itemsize)# 4
print(a)# int32
b=np.busday_count('2020-10-20','2020-12-31', weekmask='1111101')
print(b)# 62
c = np.busday_offset('2020-10-24',offsets=1, weekmask='1111100',roll='backward')
print(c)# 2020-10-26
#d = np.array([0,1,2,3,4])
#一组小括号,里边一组中括号。
# 1、中括号里边只有一串数字就是一维数组
# 2、第一级中括号里边有下一级中括号分组,就是二维数组。最里边的每一个中括号代表一行
# 3、在第二条的基础上,第二级中括号里边有小括号分组,则每个小括号里边代表一行,
# 每个第二级中括号代表三维的一个平面,第二级中括号个数=第三维度维数。
d = np.array([[(1,1.1),(2,2.2)],
[(3,3.3),(4,4.4)]])
print(d,d.dtype,type(d))
# [[[1. 1.1]
# [2. 2.2]]
# [[3. 3.3]
# [4. 4.4]]] float64 <class 'numpy.ndarray'>
def f(x,y):
return x+2*y
e=np.fromfunction(f,(3,3),dtype=int)
print(e)
# [[0 2 4]
# [1 3 5]
# [2 4 6]]
x = np.full((2,),7) #(2,)代表的是长度为2的向量
x_= np.full((2,1),7) #(2,1)代表的是两行一列的矩阵
y = np.ones((2,),dtype=int)
print(x,'\n',x_,'\n',y)
import numpy as np
import datetime
persontype=np.dtype({
'name':['name','age','weight'],
'formats':['U30','i8','f8']})
a=np.array([('li',18,65)],dtype=persontype)
print(a,type(a))
python数据类型及数组创建-笔记
最新推荐文章于 2024-05-28 16:26:21 发布