今天给大家讲解一下图像处理和深度学习里面一个常用的函数array
array的功能是接收一个多位置数,例如列表list,元
组tuple等
#列表
list1 = [[1, 2, 3]]
list2 = [[1], [2], [3]]
list3 = [(1, 2, 3)]
#元组
tuple=(1,2,3)
#打印类型
print(type(list1),type(list2),type(list3),type(tuple))
# 使用array方法
nd1 = np.array(list1)
nd2 = np.array(list2)
nd3 = np.array(list3)
nd4=np.array(tuple)
print(nd1,nd2,nd3,nd4)
运行结果:<class 'list'> <class 'list'> <class 'list'> <class 'tuple'>
[[1 2 3]] ,[[1]
[2]
[3]] ,[[1 2 3]] ,[1 2 3]
分析:1:列表镶嵌一列表转换成二维数组,行一列三
2:列表镶嵌三列表转换成二维数组,行三列一
3:列表镶嵌一元组转换成二维数组,行一列三(从外形上看不同的括号在该函数中看做相同)
4:同3解释