日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Python 程序:打印偶數(shù)位置數(shù)組元素

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

編寫(xiě)一個(gè) Python 程序,打印偶數(shù)位置或偶數(shù)索引位置的數(shù)組元素。在這個(gè) python 示例中,我們使用了遞增 2 的列表切片來(lái)打印偶數(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

在這個(gè) Python 示例中,我們使用 if 語(yǔ)句來(lái)查找偶數(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

文章名稱(chēng):Python 程序:打印偶數(shù)位置數(shù)組元素
文章路徑:http://m.5511xx.com/article/djgpsoe.html