日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:打印數(shù)組中正數(shù)

創(chuàng)新互聯(lián)Python教程:

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),明山企業(yè)網(wǎng)站建設(shè),明山品牌網(wǎng)站建設(shè),網(wǎng)站定制,明山網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,明山網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

編寫一個(gè) Python 程序,使用 for 循環(huán)范圍(或 i in range(len(posArr))打印數(shù)組中的正數(shù)。if 條件(if (posArr[i] >= 0))檢查 numpy 數(shù)組項(xiàng)是否大于或等于零。如果為真,則打印正數(shù)組項(xiàng)。

# Print Positives in Array

import numpy as np

posArr = np.array([10, -22, -14, 19, 11, -9, 0])

print("**The Positive Numbers in this posArr Array***")
for i in range(len(posArr)):
    if (posArr[i] >= 0):
        print(posArr[i], end = "  ")
**The Positive Numbers in this posArr Array***
10  19  11  0 

使用 for 循環(huán)打印數(shù)組中正數(shù)的 Python 程序

在這個(gè) Python 示例中,for 循環(huán)(posArr 中的 num)迭代原始值。在第二個(gè) for 循環(huán)中,numpy greater_equal 函數(shù)(if (np.greater_equal(i,0)= True))檢查 numpy 數(shù)組項(xiàng)是否大于或等于零并返回 True。如果為真,則打印 numpy 數(shù)組中的正數(shù)。

# Print Positive in Array

import numpy as np

posArr = np.array([1, 22, -99, -4, 14, 11, -10])

print("**The Positive Numbers in this posArr Array***")
for num in posArr:
    if (num >= 0):
        print(num, end = "  ")

print("\n\n=== Using greater equal function===")
print("**The Positive Numbers in this posArr Array***")
for i in posArr:
    if (np.greater_equal(i, 0) == True):
        print(i, end = "  ")
**The Positive Numbers in this posArr Array***
1  22  14  11  

=== Using greater equal function===
**The Positive Numbers in this posArr Array***
1  22  14  11 

Python 程序使用 while 循環(huán)返回 Numpy 數(shù)組中的正數(shù)。

# Print Positive in Array

import numpy as np

posArr = np.array([4, -5, 22, -9, -48, 11, 14])
i = 0

print("**The Positive Numbers in this posArr Array***")
while (i < len(posArr)):
    if (np.greater_equal(posArr[i], 0) == True):
        print(posArr[i], end = "  ")
    i = i + 1
**The Positive Numbers in this posArr Array***
4  22  11  14 

在這個(gè) Python numpy 數(shù)組示例中,我們創(chuàng)建了一個(gè)(def printppositivennumbers(posArr))函數(shù)來(lái)打印正數(shù)。

# Print Positive in Array

import numpy as np

def printPositiveNumbers(posArr):
    for i in posArr:
        if (np.greater_equal(i, 0) == True):
            print(i, end = "  ")

posArr = np.array([1, -11, 0, 15, -9, -17, 22, -67, 55])

print("**The Positive Numbers in this posArr Array***")
printPositiveNumbers(posArr)


名稱欄目:Python程序:打印數(shù)組中正數(shù)
URL鏈接:http://www.dlmjj.cn/article/ccdedgs.html