numpy 库的学习1
文件导入
import numpy as np
world_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter = ",")
print(type(world_alcohol))
genfromtxt()函数:从文本文件加载数据,按指定分隔符分割。
genfromtxt(fname, dtype=<class 'float'>, comments='#', delimiter=None, skip_header=0, skip_footer=0, converters=None, missing_values=None, filling_values=None, usecols=None, names=None, excludelist=None, deletechars=None, replace_space='_', autostrip=False, case_sensitive=True, defaultfmt='f%i', unpack=None, usemask=False, loose=True, invalid_raise=True, max_rows=None, encoding='bytes')
向量和矩阵
vector = np.array([5, 10, 15, 20])
matrix = np.array([[5, 10, 15],[20, 25, 30], [35, 40, 45]])
print(vector)
print(vector.shape)
print(matrix)
print(matrix.shape)