赞
踩
if __name__ == '__main__':
nd01 = np.array([1,2,3,4,5])
print(nd01)
===============================
[1 2 3 4 5]
if __name__ == '__main__':
nd01 = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
print(nd01)
===============================
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
Year,WHO region,Country,Beverage Types,Display Value
1986,Western Pacific,Viet Nam,Wine,0
1986,Americas,Uruguay,Other,0.5
1985,Africa,Cte d'Ivoire,Wine,1.62
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str")
print(nd01[0:3])
================================
[['Year' 'WHO region' 'Country' 'Beverage Types' 'Display Value']
['1986' 'Western Pacific' 'Viet Nam' 'Wine' '0']
['1986' 'Americas' 'Uruguay' 'Other' '0.5']]
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
print(nd01[0:3])
======================================
[['1986' 'Western Pacific' 'Viet Nam' 'Wine' '0']
['1986' 'Americas' 'Uruguay' 'Other' '0.5']
['1985' 'Africa' "Cte d'Ivoire" 'Wine' '1.62']]
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
res = nd01[2]
print(res)
==========================================================
['1985' 'Africa' "Cte d'Ivoire" 'Wine' '1.62']
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
res = nd01[1:4]
print(res)
==============================================================
[['1986' 'Americas' 'Uruguay' 'Other' '0.5']
['1985' 'Africa' "Cte d'Ivoire" 'Wine' '1.62']
['1986' 'Americas' 'Colombia' 'Beer' '4.27']]
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
res = nd01[:,1]
print(res)
print(type(res))
================================================
结果 : 得到一个集合 ( 一维的 ndarray )
['Western Pacific' 'Americas' 'Africa' ....]
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
res = nd01[:,1:3]
print(res)
print(type(res))
======================================
[['Western Pacific' 'Viet Nam']
['Americas' 'Uruguay']
['Africa' "Cte d'Ivoire"]
...
['Africa' 'Malawi']
['Americas' 'Bahamas']
['Africa' 'Malawi']]
if __name__ == '__main__':
# 文件名,分隔符,数据类型
nd01 = np.genfromtxt("world_alcohol.txt",delimiter=",",dtype="str",skip_header=1)
res = nd01[1:5,1:3]
print(res)
print(type(res))
==================================
[['Americas' 'Uruguay']
['Africa' "Cte d'Ivoire"]
['Americas' 'Colombia']
['Americas' 'Saint Kitts and Nevis']]
if __name__ == '__main__':
nd01 = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
res = nd01[1,2]
print(nd01)
print(res)
if __name__ == '__main__':
nd01 = np.full((2,4),1,dtype="int")
print(nd01)
==========================
[[1 1 1 1]
[1 1 1 1]]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。