2017-07-17 64 views
-3

我想打一個向量的平方,例如這個n = (1,2,3,4,5,6,7,8,9,10),並且作爲解決方案n = (1,4,9,16, 25.36,49,64,81,100)如何平鋪組件向量? Python的

+3

多德你問到基本相同的問題[這裏](https://stackoverflow.com/questions/45145640/how-to-delete-numbers-from-a-vector/45145711#45145711)。只要應用相同的邏輯。 – patrick

+1

[如何從矢量中刪除數字?](https://stackoverflow.com/questions/45145640/how-to-delete-numbers-from-a-vector)可能的重複 –

回答

1

您需要使用列表理解:

n = (1,2,3,4,5,6,7,8,9,10) 

new_n = tuple(pow(i, 2) for i in n) 

輸出:

(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)