新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
Python 程序:以逆序打印數(shù)組元素
創(chuàng)新互聯(lián)python教程:

創(chuàng)新互聯(lián)服務項目包括錫林郭勒盟網站建設、錫林郭勒盟網站制作、錫林郭勒盟網頁制作以及錫林郭勒盟網絡營銷策劃等。多年來,我們專注于互聯(lián)網行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網行業(yè)的解決方案,錫林郭勒盟網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到錫林郭勒盟省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!
編寫一個 Python 程序,以逆序打印數(shù)組元素。在這個 Python 示例中,帶有負值的列表切片以相反的順序打印 numpy 數(shù)組元素。
import numpy as np
arr = np.array([15, 25, 35, 45, 55, 65, 75])
print('Printing the Array Elements in Reverse')
print(arr[::-1])
print('\nPrinting the Array Elements')
print(arr)在這個 Python 程序中,for 循環(huán)根據索引位置從最后到第一次迭代數(shù)組元素,并以相反的順序打印數(shù)組項。
import numpy as np
arr = np.array([15, 25, 35, 45, 55, 65, 75])
print('Printing the Array Elements in Reverse')
for i in range(len(arr) - 1, -1, -1):
print(arr[i], end = ' ')Printing the Array Elements in Reverse
75 65 55 45 35 25 15Python 程序,使用 while 循環(huán)以相反的順序打印數(shù)組元素。
import numpy as np
arr = np.array([22, 44, 66, 77, 89, 11, 19])
print('Printing the Array Elements in Reverse')
i = len(arr) - 1
while i >= 0:
print(arr[i], end = ' ')
i = i - 1Printing the Array Elements in Reverse
19 11 89 77 66 44 22這個 Python 示例允許輸入 Numpy 數(shù)組元素并以相反的順序打印它們。
import numpy as np
arrlist1 = []
arrTot = int(input("Total Number of Array Elements to enter = "))
for i in range(1, arrTot + 1):
arrvalue = int(input("Please enter the %d Array Value = " %i))
arrlist1.append(arrvalue)
arr = np.array(arrlist1)
print('Printing the Array Elements in Reverse')
for i in range(len(arr) - 1, -1, -1):
print(arr[i], end = ' ')Total Number of Array Elements to enter = 9
Please enter the 1 Array Value = 21
Please enter the 2 Array Value = 34
Please enter the 3 Array Value = 65
Please enter the 4 Array Value = 78
Please enter the 5 Array Value = 98
Please enter the 6 Array Value = 34
Please enter the 7 Array Value = 65
Please enter the 8 Array Value = 87
Please enter the 9 Array Value = 99
Printing the Array Elements in Reverse
99 87 65 34 98 78 65 34 21 新聞標題:Python 程序:以逆序打印數(shù)組元素
網站網址:http://www.dlmjj.cn/article/dpcjepe.html


咨詢
建站咨詢
