0
点赞
收藏
分享

微信扫一扫

机器学习笔记--Numpy

第一章:Numpy库的使用:

1、对于数据集数据的处理

import numpy as np

world_alcohol = np.genfromtxt('world_alcohol.txt',delimiter=',',dtype=str)
# print(type(world_alcohol))
ans:<class 'numpy.ndarray'>
# print(world_alcohol.shape)
ans:(998,5) #表示数据集是由998行5列组成的
# print(world_alcohol[1,3])
ans:wine #表示输出第一行第三列的内容
# print(help(np.genfromtxt))
ans:...numpy.genfromtxt方法的用法

2、对于数组矩阵的处理

vector = np.array([5,10,15,20])
#print(vector==10)
ans:[False  True False False] #会遍历数组中的各个元素,寻找相同值的,再会返回响应的boolean值类型,若相同返回出,反之返回false

# print(vector.dtype)
ans:int32  #默认数值类型整型为int32

# print(vector.min())
ans:5  #返回最小值

vector=vector.astype(float)  #强制将类型转换为float
# print(vector.dtype)
ans:float64

# print(vector.min())
ans:5.0 #float值格式为5.0

matrix = np.array([[5,10,15],[20,25,30],[35,40,45]]
# print(matrix[:,0:2])
ans:[[ 5 10] #选中所有行,第0-1列
 [20 25]
 [35 40]]

数据集来自world_alcohol.txt,如有需要,可以联系我...

学习《机器学习》的笔记分享---来自在校大学生,若有侵权,联系我哦...

举报

相关推荐

0 条评论