可以使用Python中的列表来表示数组,并使用循环遍历每个元素进行相减操作。代码如下:

a = [1, 2, 3, 4, 5]
b = [3, 1, 4, 2, 5]

c = []
for i in range(len(a)):
    c.append(a[i] - b[i])

print(c)

输出结果为:

[-2, 1, -1, 2, 0]

其中,列表a和b表示要相减的两个数组。列表c表示相减后的新数组。循环遍历每个元素,将a和b对应位置的元素相减,并将结果追加到列表c中。最后输出列表c即可。

使用python实现两个数组相减得到新数组

原文地址: https://www.cveoy.top/t/topic/fItO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录