最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python數(shù)據(jù)分析numpy文本數(shù)據(jù)讀取索引切片實例詳解

 更新時間:2023年08月21日 09:30:24   作者:YiYa_咿呀  
這篇文章主要為大家介紹了Python數(shù)據(jù)分析numpy文本數(shù)據(jù)讀取索引切片實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

數(shù)據(jù)導入和數(shù)組轉(zhuǎn)置

np.loadtxt(framme,dtype='dataType',delimmiter='分隔符',

skiprows=''(跳過的行數(shù)'),

usecols=''需要用到的行數(shù)',

unpack='Ture/Flase(是否轉(zhuǎn)置)':加載文本文件數(shù)據(jù)

loadtxt參數(shù)意義

  • numpy數(shù)組轉(zhuǎn)置的是4種方法
    • np.loadtxt中的參數(shù)unpack值設(shè)置為TRUE
    • 使用數(shù)組的.T屬性進行轉(zhuǎn)置
    • 使用數(shù)組的transpose()方法進行轉(zhuǎn)置
    • 使用numpy數(shù)組的swapaxes方法

實例如下:

import numpy as np
filepath = './doubantop250.csv'
t1 = np.loadtxt(filepath,usecols=(1,2,3),delimiter=',',dtype='float')
print(t1)
# 轉(zhuǎn)置的四種方式
# first method:Set the value of parameter "unpack" —— True
t2 = np.loadtxt(filepath,usecols=(1,2,3),delimiter=',',dtype='float',unpack=True)
# second method: use the '.T' attributions of array's
t3 = t1.T
print(t3)
# third method: use the method of 'transpose'
t4 = t1.transpose()
print(t4)
# forth method: swapaxes(arguments:axes needed swapped)
t5 = t1.swapaxes(0,1)
print(t5)

運行結(jié)果:

numpy數(shù)組索引與切片

import numpy as np
filename = './doubantop250.csv'
t1 = np.loadtxt(filename,delimiter=',',dtype='float',usecols=(1,2,3))
# print(t1)
# 取行操作
print(t1[0])
print(t1[0,:])
# 取連續(xù)的多行
print(t1[3:])
print(t1[3:,:])
# 取不連續(xù)的多行
print(t1[[1,3,13,19]])
print(t1[[1,2,4,6],:])
# 取列
print(t1[:,0])
# 取連續(xù)的列
print(t1[:,2:])
# 取不連續(xù)的列
print(t1[:,[1,2]])
# 取第2-5行,2-3列
# 取多個位置的交叉數(shù)據(jù)
print(t1[1:5,1:3])
# 取不相鄰的位置的數(shù)據(jù)信息
print(t1[[1,4,6],[0,1,2]])
import numpy as np
filepath = './doubantop250.csv'
t1 = np.loadtxt(filepath,delimiter=',',usecols=(1,2,3))
print(t1<9.5)
t1[t1 < 9.5] = 0
print(t1[:,1])
# if-else操作
np.where(t1>=9.6,10,0)
print(t1)
# clip(m,n)把數(shù)組中小于m的替換成m,大于n的替換成n

以上就是Python數(shù)據(jù)分析numpy文本數(shù)據(jù)讀取索引切片實例詳解的詳細內(nèi)容,更多關(guān)于Python numpy數(shù)據(jù)讀取索引的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

盐津县| 卫辉市| 萨嘎县| 乐业县| 香格里拉县| 即墨市| 兴业县| 荥经县| 蓬溪县| 益阳市| 龙泉市| 蕉岭县| 寻乌县| 扬中市| 全南县| 克什克腾旗| 河间市| 自治县| 眉山市| 汉寿县| 万荣县| 连山| 南充市| 鸡东县| 卢龙县| 云浮市| 微山县| 甘肃省| 乌拉特中旗| 承德县| 商河县| 丁青县| 乌审旗| 资源县| 行唐县| 枣阳市| 湾仔区| 平阳县| 大足县| 包头市| 莱州市|