如果matrix
兼容,那么您可以(并且可能应该)将其放入numpy
数组中。它是一个非常方便的数值计算库,并带有许多功能:根据您想要做什么,您可能还想查看scipy
.
import numpy as np
a = np.array(matrix)
a += 5.5555
以一些随机数据为例:
from numpy.random import random_sample
>>> a = random_sample( (3, 3, 3) )
>>> a
array([[[ 0.98899266, 0.10761687, 0.7784259 ],
[ 0.79253918, 0.450742 , 0.46417501],
[ 0.71733034, 0.26575819, 0.19360072]],
[[ 0.41609296, 0.96195897, 0.32777537],
[ 0.59527144, 0.96655918, 0.50073892],
[ 0.70797323, 0.406036 , 0.47092251]],
[[ 0.8572665 , 0.00076713, 0.25379833],
[ 0.03426925, 0.59837259, 0.85390736],
[ 0.78306972, 0.00238982, 0.28702393]]])
>>> a += 5.55555
>>> a
array([[[ 6.54454266, 5.66316687, 6.3339759 ],
[ 6.34808918, 6.006292 , 6.01972501],
[ 6.27288034, 5.82130819, 5.74915072]],
[[ 5.97164296, 6.51750897, 5.88332537],
[ 6.15082144, 6.52210918, 6.05628892],
[ 6.26352323, 5.961586 , 6.02647251]],
[[ 6.4128165 , 5.55631713, 5.80934833],
[ 5.58981925, 6.15392259, 6.40945736],
[ 6.33861972, 5.55793982, 5.84257393]]])