Python lists
x = [1, 2, 3, 4]
y = [5, 6, 7, 8]
x * 2
[1, 2, 3, 4, 1, 2, 3, 4]
x + 10
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "int") to list
x + y
[1, 2, 3, 4, 5, 6, 7, 8]
Numpy arrays
import numpy as np
ax = np.array([1, 2, 3, 4])
ay = np.array([5, 6, 7, 8])
ax * 2
array([2, 4, 6, 8])
ax + 10
array([11, 12, 13, 14])
ax + ay
array([ 6, 8, 10, 12])
ax * ay
array([ 5, 12, 21, 32])
网友评论