numpy找出array中的最大值,最小值
在python中利用numpy建立一個array, 然後我們想獲取array的最大值,最小值。可以使用一下方法:
一、建立陣列
這樣就可以獲得一個array的最大值和最小值了。
並且可以利用np.where(np.max(a))來獲得最大值,最小值的行和列數。
二、python下對檔案的操作
1、移動一個資料夾到另一個資料夾下
首先
import os, skutil
複製檔案:
shutil.copyfile('oldfile', 'newfile') oldfile和newfile都只能是檔案
shutil.copy('oldfile', 'newfile') oldfile只能是資料夾,newfile可以是檔案,也可以是目標目錄
shutil.copytree('olddir', 'newdir') olddir和newdir都只能是目錄,且newdir必須不存在
移動檔案:
shutil.move('oldpos', 'newpos')
重新命名檔案:
os.rename('oldname', 'newname') 檔案和目錄都使用這條命令
刪除檔案:
os.remove('file')
os.rmdir('dir') 只能刪除空目錄
判斷目標:
os.path.exists('goal') 判斷目標是否存在
os.path.isdir('goal')判斷目標是否是目錄
os.path.isfile('goal')判斷目標是否是檔案
轉換目錄:
os.chdir('path')
判斷路徑是否存在:
isExists = os.path.exists(path)
存在 True
不存在 False
建立目錄:
os.mkdir('file')
建立多層目錄:
def mkdirs(path):
# 去除首位空格
path = path.strip()
# 去除尾部 \ 符號
path = path.rstrip('\\')