新聞中心
創(chuàng)新互聯(lián)python教程:

十載的泉州網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都營銷網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整泉州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“泉州網(wǎng)站設(shè)計”,“泉州網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。
編寫一個 Python 程序,使用 for 循環(huán)范圍打印 Numpy 數(shù)組中的負(fù)數(shù)(對于 I in range(len(negarar))。if 條件(if(nega rar[I]< 0))發(fā)現(xiàn) numpy 數(shù)組項小于零。如果為真,則打印該負(fù)數(shù)組項。
# Print Negatives in Array
import numpy as np
negaArr = np.array([11, -22, -33, 14, -17, 12, 0, -9, -34])
print("***The Negative Numbers in this negaArr Array***")
for i in range(len(negaArr)):
if (negaArr[i] < 0):
print(negaArr[i], end = " ")***The Negative Numbers in this negaArr Array***
-22 -33 -17 -9 -34使用 for 循環(huán)打印數(shù)組中負(fù)數(shù)的 Python 程序。
在這個 Python 示例中,for 循環(huán)(對于 negaArr 中的 num)迭代實際的 numpy 數(shù)組值。在第二個 for 循環(huán)中,numpy less 函數(shù)(if (np.less(i,0)= True))檢查 numpy 數(shù)組項是否小于零并返回 True。如果為真,則打印負(fù)數(shù)數(shù)組中的負(fù)數(shù)。
# Print Negatives in Array
import numpy as np
negaArr = np.array([1, -4, -9, 15, -22, 0, -99, 14, -10, -7, 6])
print("**The Negative Numbers in this negaArr Array***")
for num in negaArr:
if (num < 0):
print(num, end = " ")
print("\n\n=== Using less function===")
print("**The Negative Numbers in this negaArr Array***")
for i in negaArr:
if (np.less(i, 0) == True):
print(i, end = " ")Python 程序使用 While 循環(huán)返回 Numpy 數(shù)組中的負(fù)數(shù)。
# Print Negative in Array
import numpy as np
negaArr = np.array([1, -34, -77, 11, -90, 88, 65, -17, -30])
i = 0
print("**The Negative Numbers in this negaArr Array***")
while (i < len(negaArr)):
if (np.less(negaArr[i], 0) == True):
print(negaArr[i], end = " ")
i = i + 1**The Negative Numbers in this negaArr Array***
-34 -77 -90 -17 -30在這個 Python numpy 數(shù)組的例子中,我們創(chuàng)建了一個(def print negatenumbers(negarar))函數(shù)來打印負(fù)數(shù)。
# Print Negative in Array
import numpy as np
def printNegativeNumbers(negaArr):
for i in negaArr:
if (np.less(i, 0) == True):
print(i, end = " ")
negaArr = np.array([16, -99, -88, 0, -77, 44, -55, -2, 19])
print("**The Negative Numbers in this negaArr Array***")
printNegativeNumbers(negaArr)**The Negative Numbers in this negaArr Array***
-99 -88 -77 -55 -2 網(wǎng)頁題目:Python 程序:打印數(shù)組中負(fù)數(shù)
鏈接分享:http://www.5511xx.com/article/cdoejij.html


咨詢
建站咨詢
