Python numpy乘法表ouptut
我是numpy的新手,正在尝试找到一种使用numpy编写mult表的有效方法Python numpy乘法表ouptut,python,arrays,numpy,multiplication,Python,Arrays,Numpy,Multiplication,我是numpy的新手,正在尝试找到一种使用numpy编写mult表的有效方法 def mult_table(): result = [] for i in a: for j in a: result.append(i*j) return result 在numpy中,我看到一个点矩阵和一个matmul,但不确定如何复制上述逻辑。一种方法是使用。您可以轻松地将其包装到函数中 import numpy as np def mult_
def mult_table():
result = []
for i in a:
for j in a:
result.append(i*j)
return result
在numpy中,我看到一个点矩阵和一个matmul,但不确定如何复制上述逻辑。一种方法是使用。您可以轻松地将其包装到函数中
import numpy as np
def mult_table(n):
rng = np.arange(1, n+1)
return rng * rng[:, None]
print(mult_table(5))
# [[ 1 2 3 4 5]
# [ 2 4 6 8 10]
# [ 3 6 9 12 15]
# [ 4 8 12 16 20]
# [ 5 10 15 20 25]]
一种方法是使用。您可以轻松地将其包装到函数中
import numpy as np
def mult_table(n):
rng = np.arange(1, n+1)
return rng * rng[:, None]
print(mult_table(5))
# [[ 1 2 3 4 5]
# [ 2 4 6 8 10]
# [ 3 6 9 12 15]
# [ 4 8 12 16 20]
# [ 5 10 15 20 25]]
?可能的副本?可能的副本