numpy的常用函数 不断更新
生活随笔
收集整理的這篇文章主要介紹了
numpy的常用函数 不断更新
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
numpy最基本的就是數(shù)組和矩陣,先簡(jiǎn)單介紹一下數(shù)組的基本操作
1.數(shù)組
????1.1創(chuàng)建?
>>>from numpy import array >>>a1 = array([2,3,4]) >>>print(a1) [2 3 4] >>>a2 = array([[1,2,3],[4,5,6]]) >>>print(a2) [[1 2 3][4 5 6]] >>>import numpy as np >>>np.zeros((3,4)) array([[0., 0., 0., 0.],[0., 0., 0., 0.],[0., 0., 0., 0.]]) >>>np.ones((3,4)) array([[1., 1., 1., 1.],[1., 1., 1., 1.],[1., 1., 1., 1.]]) >>>np.empty((3,4)) #生成隨機(jī)數(shù) array([[1., 1., 1., 1.],[1., 1., 1., 1.],[1., 1., 1., 1.]]) >>>np.empty((3,4),dtype = np.string_) array([[b'\x01', b'\x01', b'\x01', b'\x01'],[b'\x01', b'\x01', b'\x01', b'\x01'],[b'\x01', b'\x01', b'\x01', b'\x01']], dtype='|S1')????1.2 數(shù)組的一些基本操作
>>>from numpy import shape #獲取數(shù)組的行列信息 >>>shape(a1) (3,) >>>shape(a2) (2, 3) >>>a2.shape[0] #shape[0] 數(shù)組的行信息 2 >>>a2.shape[1] #shape[1] 數(shù)組的列信息 3 >>>from numpy import tile #用來創(chuàng)建數(shù)組 ,以第一個(gè)參數(shù)作為最小單元 ,創(chuàng)建第二個(gè)參行列信息的數(shù)組 >>>aa =tile([0,1],[2,2]) >>>print(aa) [[0 1 0 1][0 1 0 1]] >>>from numpy import argsort #這是一個(gè)基本的排序 >>>tt = array([1,2,0]) >>>dst = tt.argsort() #理解一下 將tt里面的元素進(jìn)行排序 ,對(duì)應(yīng)的index放到dst數(shù)組里面 所以最小的值就是tt[dst[0]] >>>print(dst) [2 0 1] >>>print(tt) [1 2 0] >>>dst[0] 2 >>>tt[2] 0 >>>tt[dst[0]] 0 >>>tt[dst[1]] 1 >>>tt[dst[2]] 2總結(jié)
以上是生活随笔為你收集整理的numpy的常用函数 不断更新的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转;VC++中Format函数详解
- 下一篇: leetcode-Minimum Siz