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

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

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

編寫一個 Python 程序,打印偶數(shù)位置或偶數(shù)索引位置的數(shù)組元素。在這個 python 示例中,我們使用了遞增 2 的列表切片來打印偶數(shù)位置的數(shù)組元素。

import numpy as np

arr = np.array([2, 4, 6, 8, 12, 14, 16, 18])

print('Printing the Array Elements at Even Position')
print(arr[1:len(arr):2])

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

import numpy as np

arr = np.array([22, 44, 66, 88, 122, 144, 166, 188])

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

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

import numpy as np

arr = np.array([11, 13, 15, 17, 19, 22, 39])

print('Printing the Array Elements at Even Position')
i = 1
while i < len(arr):
    print(arr[i], end = '  ')
    i = i + 2
Printing the Array Elements at Even Position
13  17  22

在這個 Python 示例中,我們使用 if 語句來查找偶數(shù)索引位置,并打印偶數(shù)位置上存在的數(shù)組元素。

import numpy as np

evarrlist = []
evarrTot = int(input("Total Array Elements to enter = "))

for i in range(1, evarrTot + 1):
    evarrvalue = int(input("Please enter the %d Array Value = "  %i))
    evarrlist.append(evarrvalue)

evarr = np.array(evarrlist)

print('\nPrinting the Array Elements at Even Position')
for i in range(1, len(evarr), 2):
    print(evarr[i], end = '  ')

print('\nPrinting the Array Elements at Even Position')
for i in range(len(evarr)):
    if i % 2 != 0:
        print(evarr[i], end = '  ')
Total Array Elements to enter = 9
Please enter the 1 Array Value = 22
Please enter the 2 Array Value = 43
Please enter the 3 Array Value = 56
Please enter the 4 Array Value = 23
Please enter the 5 Array Value = 65
Please enter the 6 Array Value = 98
Please enter the 7 Array Value = 56
Please enter the 8 Array Value = 11
Please enter the 9 Array Value = 99

Printing the Array Elements at Even Position
43  23  98  11  
Printing the Array Elements at Even Position
43  23  98  11

文章名稱:Python 程序:打印偶數(shù)位置數(shù)組元素
鏈接地址:http://uogjgqi.cn/article/djgpsoe.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

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