numpy 庫(kù)的學(xué)習(xí)1
文件導(dǎo)入
import numpy as np
world_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter = ",")
print(type(world_alcohol))
genfromtxt()函數(shù):從文本文件加載數(shù)據(jù),按指定分隔符分割碾盟。
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)