python數(shù)學建模是加深Numpy和Pandas學習
前言
今天我看到線性規(guī)劃模型開頭的介紹,特別不錯,因此,我把它記錄下來了,分享給大家
在工程技術(shù)、經(jīng)濟管理、科學研究、軍事作戰(zhàn)訓練及日常生活等眾多領域,人們常常會遇到各種優(yōu)化問題。例如,在生產(chǎn)經(jīng)營中,我們總是希望制定最優(yōu)的生產(chǎn)計劃,充分利用已有的人力、物力資源,獲得最大的經(jīng)濟效益;在運輸問題中,我們總是希望設計最優(yōu)的運輸方案,在完成運輸任務的前提下,力求運輸成本最小等。【針對優(yōu)化問題的數(shù)學建模問題也是數(shù)學建模競賽中一類比較常見的問題,這樣的問題常常可以使用數(shù)學規(guī)劃模型進行研究。】
數(shù)學規(guī)劃是運籌學的一個重要分支,而線性規(guī)劃又是數(shù)學規(guī)劃中的一部分主要內(nèi)容。很多實際問題都可以歸結(jié)為“線性規(guī)劃”問題。線性規(guī)劃有比較完善的理論基礎和有效的求解方法,在實際問題中有極其廣泛地應用。特別是隨著計算機技術(shù)的飛速發(fā)展,線性規(guī)劃的應用在深度和廣度上有了極大的提高。
上一篇文章python數(shù)學建模之Numpy 應用介紹與Pandas學習
Numpy 學習
# Numpy的基本使用
'''
Numpy提供了兩種基本的對象:ndarray存儲單一數(shù)據(jù)類型的多維數(shù)組;
ufunc是能夠?qū)?shù)組進行處理的函數(shù)
1-導入函數(shù)
import numpy as np
2-數(shù)組創(chuàng)建
2-1 array 可將列表或元組轉(zhuǎn)化為ndarray數(shù)組
2-2 arange 在給定區(qū)間內(nèi)創(chuàng)建等差數(shù)組,格式:
arange(start=None, stop=None, step=None,dtype=None)
【step表示步長間隔】
2-3 linspace 在給定區(qū)間內(nèi)創(chuàng)建間隔相等的數(shù)組,格式:
linspace(start, stop, num=50, endpoint=True)
【間隔相等的num個數(shù)據(jù),其num默認值是50】
2-4 logspace 在給定區(qū)間內(nèi)生成等比數(shù)組,格式:
logspace(start, stop, num=50, endpoint=True, base=10.0)
【默認生成區(qū)間[10start(次方), 10stop()次方]上的num個數(shù)據(jù)的等比數(shù)組】
以及 ones、zeros、empty和ones_like等系列函數(shù)的運用:
'''1-numpy.array
# numpy.array
# array()函數(shù),括號內(nèi)可以是列表、元組、數(shù)組、迭代對象、生成器
import numpy as np
print(np.array([6, 6, 6])) # 列表
print(np.array((8, 8, 8))) # 元組
print(np.array(np.array([9, 9, 9]))) # 數(shù)組
print(np.array(range(10))) # 迭代對象 / 整型
print(np.array([i**2 for i in range(10)])) # 生成器
# 創(chuàng)建10以內(nèi)的奇數(shù)的數(shù)組:
print(np.array([i for i in range(1, 10, 2)]))
print(np.array([i for i in range(10) if i % 2 != 0]))
# 創(chuàng)建10以內(nèi)的偶數(shù)的數(shù)組:
print(np.array([i for i in range(0, 10, 2)]))
print(np.array([i for i in range(10) if i % 2 == 0]))
# 列表中元素類型不相同
print(np.array([5, 2, '0'])) # ['5' '2' '0']
# 浮點型
print(np.array([3, 4, 5.2]))
# 二維數(shù)組:【嵌套序列(列表、元組均可)】
print(np.array([[6, 7, 8], ('lxw', 'cw', 'wl')]))
print(np.array([[6, 7, 8], ('lxw', 'cw', 'wl')]).ndim) # ndim(維度): 2
# 嵌套數(shù)量不一致:【強制轉(zhuǎn)化為一維,推薦不用】
print(np.array([[6, 7, 8], ('lxw', 'cw', 'wl', 'npy')], dtype=object))
print(np.array([[6, 7, 8], ('lxw', 'cw', 'wl', 'npy')], dtype=object).ndim) # ndim(維度):1
print(np.array([[6, 7, 8], ('lxw', 'cw', 'wl', 'npy')], dtype=object).shape) # 運行結(jié)果:(2,)
print(np.array([[6, 7, 8], [9, 9, 6, 9]], dtype=object))
print(np.array([[6, 7, 8], [9, 9, 6, 9]], dtype=object).ndim) # ndim(維度):1
print(np.array([[6, 7, 8], [9, 9, 6, 9]], dtype=object).shape) # 運行結(jié)果:(2,) -> 代表兩行一列2-numpy.empty
# numpy.empty ''' numpy.empty 方法用來創(chuàng)建一個指定形狀(shape)、數(shù)據(jù)類型(dtype)且未初始化的數(shù)組 numpy.empty(shape, dtype = float, order = 'C') 參數(shù)說明: 參數(shù) 描述 shape 數(shù)組形狀 dtype 數(shù)據(jù)類型,可選 order 有"C"和"F"兩個選項,分別代表,行優(yōu)先和列優(yōu)先,在計算機內(nèi)存中的存儲元素的順序 ''' import numpy as np lxw = np.empty([3, 4], dtype=int) print(lxw) # 注意:數(shù)組元素為隨機值,因為它們未初始化
3-numpy.zeros
# numpy.zeros
'''
創(chuàng)建指定大小的數(shù)組,數(shù)組元素以 0 來填充:
numpy.zeros(shape, dtype = float, order = 'C')
參數(shù)說明:
order : 'C' 用于 C 的行數(shù)組,或者 'F' 用于 FORTRAN 的列數(shù)組
'''
import numpy as np
lxw = np.zeros(6) # 默認為浮點數(shù)
print(lxw)
lxw2 = np.zeros((6, ), dtype=int) # 設置類型為整數(shù)
print(lxw2)
# 自定義類型
lxw3 = np.zeros((2, 2), dtype=[('lxw', 'i2'), ('lxw2', 'i4')])
print(lxw3)4-numpy.ones
# numpy.ones '''創(chuàng)建指定形狀的數(shù)組,數(shù)組元素以 1 來填充: numpy.ones(shape, dtype = None, order = 'C') ''' import numpy as np lxw4 = np.ones(8) # 默認浮點數(shù) print(lxw4) lxw5 = np.ones([2, 2], dtype=int) print(lxw5)
NumPy 從已有的數(shù)組創(chuàng)建數(shù)組
1-numpy.asarray
# numpy.asarray ''' numpy.asarray 類似 numpy.array,但 numpy.asarray 參數(shù)只有三個,比 numpy.array 少兩個。 numpy.asarray(a, dtype = None, order = None) 參數(shù)說明: 參數(shù) 描述 a 任意形式的輸入?yún)?shù),可以是,列表, 列表的元組, 元組, 元組的元組, 元組的列表,多維數(shù)組 ''' # 將列表轉(zhuǎn)換為 ndarray: import numpy as np x = [5, 2, 0] lxw6 = np.asarray(x) print(lxw6) # 將元組轉(zhuǎn)換為 ndarray import numpy as np x2 = (1, 3, 1, 4) lxw7 = np.asarray(x2) print(lxw7) # 設置了 dtype 參數(shù) import numpy as np x4 = [6, 6, 9] lxw9 = np.asarray(x4, dtype=float) print(lxw9)
2-numpy.frombuffer
# numpy.frombuffer ''' numpy.frombuffer 用于實現(xiàn)動態(tài)數(shù)組;接受 buffer 輸入?yún)?shù),以流的形式讀入轉(zhuǎn)化成 ndarray 對象。 格式如下: numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0) 注:buffer 是字符串的時候,Python3 默認 str 是 Unicode 類型,所以要轉(zhuǎn)成 bytestring 在原 str 前加上 b。 參數(shù)說明: 參數(shù) 描述 buffer 可以是任意對象,會以流的形式讀入。 dtype 返回數(shù)組的數(shù)據(jù)類型,可選 count 讀取的數(shù)據(jù)數(shù)量,默認為-1,讀取所有數(shù)據(jù)。 offset 讀取的起始位置,默認為0 ''' import numpy as np s = b'lxw_pro' lxw10 = np.frombuffer(s, dtype='S1') print(lxw10)
3-numpy.fromiter
# numpy.fromiter ''' numpy.fromiter 方法從可迭代對象中建立 ndarray 對象,返回一維數(shù)組。 numpy.fromiter(iterable, dtype, count=-1) ''' import numpy as np lst = range(6) it = iter(lst) lxw11 = np.fromiter(it, dtype=float) print(lxw11)
NumPy 從數(shù)值范圍創(chuàng)建數(shù)組
1-numpy.arange
# numpy.arange ''' numpy 包中的使用 arange 函數(shù)創(chuàng)建數(shù)值范圍并返回 ndarray 對象,函數(shù)格式如下: numpy.arange(start, stop, step, dtype) 根據(jù) start 與 stop 指定的范圍以及 step 設定的步長,生成一個 ndarray。 參數(shù)說明: 參數(shù) 描述 start 起始值,默認為0 stop 終止值(不包含) step 步長,默認為1 dtype 返回ndarray的數(shù)據(jù)類型,如果沒有提供,則會使用輸入數(shù)據(jù)的類型 ''' # 生成0和5的數(shù)組 import numpy as np a = np.arange(6) print(a) # 設置返回類型位 float import numpy as np a2 = np.arange(6, dtype=float) print(a2) # 設置了起始值、終止值及步長 import numpy as np a3 = np.arange(20, 52, 5) print(a3)
2-numpy.linspace
# numpy.linspace ''' numpy.linspace 函數(shù)用于創(chuàng)建一個一維數(shù)組,數(shù)組是一個等差數(shù)列構(gòu)成的,格式如下: np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None) 參數(shù)說明: 參數(shù) 描述 start 序列的起始值 stop 序列的終止值,如果endpoint為true,該值包含于數(shù)列中 num 要生成的等步長的樣本數(shù)量,默認為50 endpoint 該值為 true 時,數(shù)列中包含stop值,反之不包含,默認是True。 retstep 如果為 True 時,生成的數(shù)組中會顯示間距,反之不顯示。 dtype ndarray 的數(shù)據(jù)類型 ''' # 類似等差數(shù)列 import numpy as np a4 = np.linspace(1, 10, 5) print(a4) # 設置元素全部是1的等差數(shù)列 import numpy as np a5 = np.linspace(1, 1, 10) print(a5) # 將 endpoint 設為 false,不包含終止值 import numpy as np a6 = np.linspace(8, 22, 4, endpoint=False) print(a6) # 注:將 endpoint 設為 true,則會包含 22 a6 = np.linspace(8, 22, 4, endpoint=True) print(a6) # 設置間距 import numpy as np a7 = np.linspace(5, 10, 5).reshape([5, 1]) print(a7)
3-numpy.logspace
# numpy.logspace ''' numpy.logspace 函數(shù)用于創(chuàng)建一個于等比數(shù)列。格式如下: np.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None) base 參數(shù)意思是取對數(shù)的時候 log 的下標。 參數(shù) 描述 start 序列的起始值為:base ** start stop 序列的終止值為:base ** stop。如果endpoint為true,該值包含于數(shù)列中 num 要生成的等步長的樣本數(shù)量,默認為50 endpoint 該值為 true 時,數(shù)列中中包含stop值,反之不包含,默認是True。 base 對數(shù) log 的底數(shù)。 dtype ndarray 的數(shù)據(jù)類型 ''' import numpy as np a8 = np.logspace(1, 2, num=10) # 默認底數(shù)是 10 print(a8) # 將對數(shù)的底數(shù)設置為 2 import numpy as np a9 = np.logspace(0, 8, 9, base=2) print(a9)
綜合運用【array、arange、linspace、lonspace】:
# 綜合運用
import numpy as np
ltw = np.array([3, 3, 4, 4]) # 生成整型數(shù)組
ltw2 = ltw.astype(float) # 轉(zhuǎn)為浮點數(shù)
ltw3 = np.array([5, 2, 1], dtype=float) # 浮點數(shù)
print(ltw)
print(ltw2)
print(ltw3)
# 比較類型
print(ltw.dtype, ltw2.dtype, ltw3.dtype)
aa = np.array([
[2, 5, 8],
[9, 6, 2]
])
print(aa)
bb = np.arange(2, 9)
print(bb) # 運行結(jié)果為:[2 3 4 5 6 7 8]
cc = np.linspace(2, 5, 4)
print(cc) # 運行結(jié)果為:[2. 3. 4. 5.]
dd = np.logspace(1, 4, 4, base=2) # base控制的是幾次方
print(dd) # 運行結(jié)果為:[ 2. 4. 8. 16.]綜合運用【ones、zeros、empty、ones_like】
# 綜合運用【ones、zeros、empty、ones_like】 import numpy as np a = np.ones(6, dtype=int) print(a) # 運行結(jié)果為:[1 1 1 1 1 1] b = np.ones((6,), dtype=int) print(b) # 運行結(jié)果為:[1 1 1 1 1 1] c = np.ones((3, 1)) print(c) # 輸出3行一列的數(shù)組 # 運行結(jié)果為: # [[1.] # [1.] # [1.]] d = np.zeros(4) print(d) # 運行結(jié)果為:[0. 0. 0. 0.] e = np.empty(3) print(e) # 生成3個元素的空數(shù)組行向量 # 運行結(jié)果為:[1. 1. 1.] f = np.eye(3) print(f) # 生成3階單位陣 # 運行結(jié)果為: # [[1. 0. 0.] # [0. 1. 0.] # [0. 0. 1.]] g = np.eye(3, k=1) print(g) # 生成第k對角線的元素為1,其他元素為0的3階方陣 # 運行結(jié)果為: # [[0. 1. 0.] # [0. 0. 1.] # [0. 0. 0.]] h = np.zeros_like(b) print(h) # 生成與a同維數(shù)的全0數(shù)組 # 運行結(jié)果為:[0 0 0 0 0 0]
1. NumPy 切片和索引
# NumPy 切片和索引
'''
ndarray對象的內(nèi)容可以通過索引或切片來訪問和修改,與 Python 中 list 的切片操作一樣。
ndarray 數(shù)組可以基于 0 - n 的下標進行索引,
切片對象可以通過內(nèi)置的 slice 函數(shù),并設置 start, stop 及 step 參數(shù)進行,從原數(shù)組中切割出一個新數(shù)組
'''
import numpy as np
# 通過 arange() 函數(shù)創(chuàng)建 ndarray 對象
a = np.arange(10)
lxw = slice(2, 9, 3) # 索引從2到9,間隔為3
print(a[lxw]) # [2 5 8]
# 通過切片操作
a = np.arange(10)
lxw2 = a[2:9:3] # 這里的切片操作和Python中l(wèi)ist的操作是一樣的
print(lxw2) # [2 5 8]
# 比如:
import numpy as np
lxw3 = np.arange(10)
print(lxw3[6]) # 6
print(lxw3[6:]) # [6 7 8 9]
print(lxw3[2:7]) # [2 3 4 5 6]
# 多維數(shù)組同樣適用上述索引提取方法
import numpy as np
lxw4 = np.array([
[6, 6, 6],
[5, 2, 0],
[5, 8, 9]
])
print(lxw4)
print(lxw4[1:])
# 切片還可以包括省略號 …,來使選擇元組的長度與數(shù)組的維度相同。
# 如果在行位置使用省略號,它將返回包含行中元素的 ndarray
import numpy as np
lxw5 = np.array([
[1, 2, 9],
[2, 5, 4],
[3, 4, 8]
])
print(lxw5[1, ...]) # [2 5 4] 第二行元素
print(lxw5[..., 2]) # [9 4 8] 第三列元素
print(lxw5[1:, ...]) # 第二行及剩下元素
print(lxw5[..., 1:]) # 第二列及剩下元素NumPy 高級索引
- Numpy中的
array數(shù)組與Python基礎數(shù)據(jù)結(jié)構(gòu)列表(list)的區(qū)別是: - 列表中的元素可以是不同的數(shù)據(jù)類型array數(shù)組只允許存儲相同的數(shù)據(jù)類型
NumPy 比一般的 Python 序列提供更多的索引方式。
- 除了之前看到的用整數(shù)和切片的索引外,數(shù)組可以由
- 整數(shù)數(shù)組索引布爾索引花式索引
1-整數(shù)數(shù)組索引
# 1-整數(shù)數(shù)組索引
import numpy as np
b = np.array([
[6, 2, 9],
[4, 3, 9],
[5, 2, 3]
])
lxw6 = b[
[0, 1, 2], [1, 2, 1]
]
print(lxw6) # 輸出 [2 9 2]
# 獲取四個角元素
import numpy as np
aq = np.array([
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6],
[4, 5, 6, 7]
])
print(aq)
hj = np.array([[0, 0], [3, 3]])
lj = np.array([[0, 3], [0, 3]])
yq = aq[hj, lj]
print(yq)
print()
# 可借助切片 : 或 … 與索引數(shù)組組合:
import numpy as np
jz = np.array([
[3, 5, 9],
[5, 2, 6],
[2, 9, 8]
])
jz1 = jz[:2, :2]
print(jz1)
jz2 = jz[:2, [0, 1]]
print(jz2)
jz3 = jz[..., 1:]
print(jz3)2-布爾索引
# 布爾索引
# 布爾索引可通過布爾運算(如:比較運算符)來獲取符合指定條件的元素的數(shù)組
# 獲取大于5的元素:
import numpy as np
br = np.array([
[6, 7, 8],
[5, 2, 1],
[6, 6, 9],
[2, 4, 5]
])
print(br)
print(br[br > 5]) # 輸出 [6 7 8 6 6 9]
# 使用 ~(取補運算符)來過濾 NaN:
import numpy as np
bu = np.array([5, np.nan, 2, 0, np.nan, np.nan, 5, 8])
print(bu[~np.isnan(bu)]) # 輸出 [5. 2. 0. 5. 8.]
# 從數(shù)組中過濾掉非復數(shù)元素:
import numpy as np
lv = np.array([2+2.9j, 4, 9, 2+8.2j, 8])
print(lv[np.iscomplex(lv)]) # 輸出 [2.+2.9j 2.+8.2j]3-花式索引
# 花式索引【利用整數(shù)數(shù)組進行索引】 # 花式索引根據(jù)索引數(shù)組的值作為目標數(shù)組的某個軸的下標來取值。 # 對于使用一維整型數(shù)組作為索引,如果目標是一維數(shù)組,那么索引的結(jié)果就是對應下標的行, # 如果目標是二維數(shù)組,那么就是對應位置的元素。 # 注:花式索引跟切片不一樣,它總是將數(shù)據(jù)復制到新數(shù)組中。 # 1.傳入順序索引數(shù)組 import numpy as np sx = np.arange(32).reshape(8, 4) print(sx[[5, 2, 1, 6]]) # 2.傳入倒序索引數(shù)組 import numpy as np dx = np.arange(32).reshape(8, 4) print(dx[[-5, -2, -1, -6]]) # 3.傳入多個索引數(shù)組(要使用np.ix_) import numpy as np dg = np.arange(32).reshape(8, 4) print(dg[np.ix_([2, 3, 5, 1], [3, 2, 0, 1])])
三個實用小方法:
- 條件加小括號
- 使用np.logical_and方法
- 使用np.all方法
import numpy as np
sy = np.array([
[3, 5, 6],
[2, 6, 2],
[5, 2, 0],
[3, 3, 4]
])
# 原數(shù)組
print(sy)
# 1-
print(sy[(sy > 3) & (sy < 6)]) # 條件記得加小括號
# 2-
print(sy[np.logical_and(sy > 3, sy < 6)])
# 3-
print(sy[np.all([sy > 3, sy < 6], axis=0)])綜合運用【數(shù)組元素的索引】
相關(guān)代碼如下:
import numpy as np x = np.arange(16).reshape(4, 4) print(x) # 生成4行4列的數(shù)組 x2 = x[2][1] print(x2) # 輸出 9 x3 = x[2, 1] print(x3) # 輸出 9 x4 = x[1:2, 2:4] print(x4) # 輸出 [[6 7]] xx = np.array([0, 1, 2, 1]) print(x[xx == 1]) # 輸出x的第2、4行元素
Pandas學習(續(xù))
# Pandas學習(續(xù)) # Pandas庫是在Numpy庫基礎上開發(fā)的一種數(shù)據(jù)分析工具 ''' Pandas主要提供了三種數(shù)據(jù)結(jié)構(gòu): 1-Series: 帶標簽的一維數(shù)組 2-DataFrame: 帶標簽且大小可變得二維表格結(jié)構(gòu) 3-Panel: 帶標簽且大小可變得三維數(shù)組 ''' # 生成二維數(shù)組 # 生成服從標準正態(tài)分布的24*4隨機數(shù)矩陣,并保存為DataFrame數(shù)據(jù)結(jié)構(gòu)。 import pandas as pd import numpy as np dates = pd.date_range(start='20220622', end='20220707', freq='D') print(dates)
運行效果如下:

lxw1 = pd.DataFrame(np.random.randn(16, 4), index=dates, columns=list('ABCD'))
lxw2 = pd.DataFrame(np.random.randn(16, 4))
print(lxw1)
print(lxw2)運行結(jié)果如下:


1 將數(shù)據(jù)寫入excel、csv文件
# 將lxw1的數(shù)據(jù)寫入excel文件
lxw1.to_excel('假期培訓時間.xlsx')
lxw1.to_excel("時間任意.xlsx", index=False) # 不包含行索引
# 將lxw2的數(shù)據(jù)寫入csv文件
lxw2.to_csv('假期培訓時間.csv')
lxw2.to_csv("時間隨意.csv", index=False) # 不包含行索引
# 創(chuàng)建文件對象
f = pd.ExcelWriter('培訓時間(格式).xlsx')
# 把lxw1寫入Excel文件
lxw1.to_excel(f, "Shell1")
# 把lxw2寫入Excel文件
lxw2.to_excel(f, "Sheet2")
f.save()部分效果圖如下:


# 從文件中讀入數(shù)據(jù):
import pandas as pd
lxw3 = pd.read_csv("假期培訓時間.csv", usecols=range(1, 4))
print(lxw3)運行結(jié)果如下:

lxw4 = pd.read_excel("培訓時間(格式).xlsx", "Sheet2", usecols=range(1, 3))
print(lxw4)
2 數(shù)據(jù)的一些預處理
# 數(shù)據(jù)的一些預處理
# DataFrame數(shù)據(jù)的拆分、合并和分組計算:
import pandas as pd
import numpy as np
lxw5 = pd.DataFrame(np.random.randint(1, 6, (10, 4)), columns=list('ABCD'))
print(lxw5)
lxww = lxw5[:5] # 獲取前五行數(shù)據(jù) print(lxww)

lxwy = lxw5[5:] # 獲取第六行以后的數(shù)據(jù) print(lxwy)

wy = pd.concat([lxww, lxwy]) # 數(shù)據(jù)行合并 print(wy)

q1 = lxw5.groupby('A').mean() # 數(shù)據(jù)分組求均值
print(np.around(q1, decimals=2)) # decimals表示保留幾位小數(shù)
q2 = lxw5.groupby('A').apply(sum) # 數(shù)據(jù)分組求和
print(q2)
3 數(shù)據(jù)的選取與操作
# 數(shù)據(jù)的選取與操作
'''
對DataFrame進行選取,要從3個層次考慮:行列、區(qū)域、單元格
1-選用中括號[]選取行列
2-使用行和列的名稱進行標簽定位的df.loc[]
3-使用整型索引(絕對位置索引)的df.iloc[]
當然,在數(shù)據(jù)預處理中,需要對缺失值等進行一些特殊處理
'''
# 數(shù)據(jù)操作:
import pandas as pd
import numpy as np
qq = pd.DataFrame(np.random.randint(1, 5, (6, 4)),
index=['a', 'b', 'c', 'd', 'e', 'f'],
columns=['one', 'two', 'three', 'four'])
qq.loc['c', 'two'] = np.nan # 修改第三行第二列的數(shù)據(jù)
print(qq)
ww = qq.iloc[1:4, 0:2] # 提取第二、三、四行,第一、二列數(shù)據(jù) print(ww)

qq['five'] = 'lxw' # 增加第五列數(shù)據(jù) print(qq)

qq2 = qq.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g']) # 增加行名 print(qq2)

qq3 = qq2.dropna() # 刪除有不確定值的行 print(qq3) # 從輸出不難看出,刪除了c行和g行

遇到的問題:
- 1-代碼運行錯誤是很正常的事,只要自己能解決,那遲早也是對的,是吧!每次運行錯誤,我都會自己先找找原因,要么多看幾眼代碼,要么直接復制運行報錯的代碼,去百度翻譯自己查查是什么意思,在結(jié)合意思查詢相關(guān)資料以修正代碼!
- 2-后面再去看看【模型與算法】,發(fā)現(xiàn) 自己所存儲的知識不夠,所以還得繼續(xù)學習新的知識,一次一次地突破!
總結(jié):
面臨著一次次的運行錯誤,一次又一次的解決,或許解決的難題越多,你懂的就會越來越多吧,就如同你經(jīng)歷的一樣,你經(jīng)歷的越多,知道的就越多!
到此這篇關(guān)于python數(shù)學建模是加深Numpy學習的文章就介紹到這了,更多相關(guān)python Numpy內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python學習教程之Numpy和Pandas的使用
- python安裝numpy和pandas的方法步驟
- 淺談python已知元素,獲取元素索引(numpy,pandas)
- python統(tǒng)計函數(shù)庫scipy.stats的用法解析
- python scipy 稀疏矩陣的使用說明
- Python使用scipy.fft進行大學經(jīng)典的傅立葉變換
- python scipy.spatial.distance 距離計算函數(shù) ?
- 詳解Python如何利用Pandas與NumPy進行數(shù)據(jù)清洗
- python數(shù)學建模之Numpy?應用介紹與Pandas學習
- python數(shù)學建模(SciPy+?Numpy+Pandas)
相關(guān)文章
如何使用draw.io插件在vscode中一體化導出高質(zhì)量圖片
這篇文章主要介紹了draw.io插件在vscode中一體化導出高質(zhì)量圖片需要的工具是vscode,?draw.io擴展,draw.io桌面版?、python,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒,需要的朋友可以參考下2022-08-08
python實現(xiàn)Dijkstra靜態(tài)尋路算法
這篇文章主要介紹了python實現(xiàn)Dijkstra靜態(tài)尋路算法,常用于路由算法或者作為其他圖算法的一個子模塊,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01
python調(diào)用cmd命令時遇到的路徑空格問題和中文亂碼的解決
這篇文章主要介紹了python調(diào)用cmd命令時遇到的路徑空格問題和中文亂碼的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
Python源碼學習之PyObject和PyTypeObject
今天給大家?guī)淼氖顷P(guān)于Python源碼的相關(guān)知識學習,文章圍繞著PyObject和PyTypeObject展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下2021-06-06
Python使用Selenium執(zhí)行JavaScript代碼的步驟詳解
Selenium是一個用于自動化瀏覽器操作的工具,可以模擬人工操作,執(zhí)行各種瀏覽器操作,而JavaScript是一種常用的腳本語言,本文將介紹如何在Python中使用Selenium執(zhí)行JavaScript代碼,并給出一些常見的應用示例2023-11-11
Python之a(chǎn)scii轉(zhuǎn)中文的實現(xiàn)
這篇文章主要介紹了Python之a(chǎn)scii轉(zhuǎn)中文的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05

