Skip to main content
 首页 » 编程设计

python之在 Python 中对数字列表(或数组)进行平方

2025年05月04日11lonelyxmas

<分区>

我来自 MATLAB 背景,根据其他堆栈中的答案,到目前为止,这个简单的操作在 Python 中实现似乎非常复杂。通常,大多数答案都使用 for 循环。

到目前为止我看到的最好的是

import numpy 
start_list = [5, 3, 1, 2, 4] 
b = list(numpy.array(start_list)**2) 

有没有更简单的方法?