Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

Addition of elements of array in python array.array

Given an array?A?of?N?numbers (integers), you have to write a program that prints the sum of the elements of array?A?with the corresponding elements of the reverse of array?A. If array?A?has elements?[1, 2, 3], then reverse of the array?A?will be?[3, 2, 1]?and the resultant array should be?[4, 4, 4].

from array import *

vals=array('i', [1,2,3 ])

vals2=array('i', [])

vals2.typecode=vals.reverse()

newArr=array(vals.typecode,(a+vals2 for a in vals))

for e in newArr:
    print(e)

output:

Traceback (most recent call last):
  File "E:/colg/python/Fristpro.py", line 7, in <module>
    vals2.typecode=vals.reverse()
AttributeError: attribute 'typecode' of 'array.array' objects is not writable
question from:https://stackoverflow.com/questions/65559619/addition-of-elements-of-array-in-python-array-array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...