av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:打印奇數(shù)位置數(shù)組元素

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

成都創(chuàng)新互聯(lián)公司長(zhǎng)期為超過千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為南海企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站制作,南海網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

編寫一個(gè) Python 程序,打印奇數(shù)位置或奇數(shù)索引位置的數(shù)組元素。在這個(gè) Python 示例中,列表切片從 0 開始,然后遞增 2。

import numpy as np

arr = np.array([1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21])

print('Printing the Array Elements at Odd Position')
print(arr[0:len(arr):2])
Printing the Array Elements at Odd Position
[ 1  5  9 13 17 21]

使用 for 循環(huán)打印奇數(shù)索引位置的數(shù)組元素的 Python 程序。

import numpy as np

arr = np.array([10, 25, 20, 33, 40, 55, 60, 77])

print('Printing the Array Elements at Even Position')
for i in range(0, len(arr), 2):
    print(arr[i], end = '  ')

Python 程序,使用 while 循環(huán)打印奇數(shù)位置的數(shù)組元素。

import numpy as np

odarr = np.array([3, 9, 11, 4, 22, 8, 99, 19, 7])

print('Printing the Array Elements at Odd Position')
i = 0
while i < len(odarr):
    print(odarr[i], end = '  ')
    i = i + 2
Printing the Array Elements at Odd Position
3  11  22  99  7 

在這個(gè) Python 示例中,if 語句(如果 i % 2 == 0)找到奇數(shù)索引位置,并打印出現(xiàn)在奇數(shù)位置的數(shù)組元素。

import numpy as np

odarrlist = []
odarrTot = int(input("Total Array Elements to enter = "))

for i in range(1, odarrTot + 1):
    odarrvalue = int(input("Please enter the %d Array Value = "  %i))
    odarrlist.append(odarrvalue)

odarr = np.array(odarrlist)

print('Printing the Array Elements at Odd Position')
for i in range(0, len(odarr), 2):
    print(odarr[i], end = '  ')

print('\nPrinting the Array Elements at Odd Position')
for i in range(len(odarr)):
    if i % 2 == 0:
        print(odarr[i], end = '  ')
Total Array Elements to enter = 9
Please enter the 1 Array Value = 17
Please enter the 2 Array Value = 22
Please enter the 3 Array Value = 33
Please enter the 4 Array Value = 45
Please enter the 5 Array Value = 56
Please enter the 6 Array Value = 76
Please enter the 7 Array Value = 78
Please enter the 8 Array Value = 89
Please enter the 9 Array Value = 90
Printing the Array Elements at Odd Position
17  33  56  78  90  
Printing the Array Elements at Odd Position
17  33  56  78  90 

名稱欄目:Python程序:打印奇數(shù)位置數(shù)組元素
分享地址:http://uogjgqi.cn/article/dpsejhg.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流