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

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

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

數(shù)據(jù)導(dǎo)入和數(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屬性進(jìn)行轉(zhuǎn)置
    • 使用數(shù)組的transpose()方法進(jìn)行轉(zhuǎn)置
    • 使用numpy數(shù)組的swapaxes方法

實(shí)例如下:

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)

運(yùn)行結(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列
# 取多個(gè)位置的交叉數(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ù)讀取索引切片實(shí)例詳解的詳細(xì)內(nèi)容,更多關(guān)于Python numpy數(shù)據(jù)讀取索引的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論

尼勒克县| 盘山县| 阳朔县| 荣昌县| 酒泉市| 元朗区| 汽车| 玉溪市| 红河县| 德兴市| 洪江市| 图们市| 台北县| 柘荣县| 滦平县| 剑阁县| 仙桃市| 涟水县| 东光县| 黎川县| 陵川县| 台州市| 马公市| 昌都县| 天祝| 四会市| 亚东县| 阳高县| 南溪县| 新巴尔虎左旗| 开远市| 盘山县| 高青县| 措勤县| 酒泉市| 泽库县| 土默特右旗| 汝城县| 乐山市| 资阳市| 腾冲县|