欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

求助!被python折腾到头秃啊!!

程序员文章站 2022-12-21 08:18:48
在学习python矩阵相关内容的时候,根据例子编程如下:from numpy import *a_1 = [1,2,3]a_2 = [4,5,6]a_3 = [7,8,9]a10 = mat([a_1,a_2,a_3])x = a10.sum(axis=0)print('sum column is',x)y = a10.sum(axis=1)print('sum row is',y)z = sum(a10[0,:])print('sum first row is',z)#最大值最...

在学习python矩阵相关内容的时候,根据例子编程如下:

from numpy import *
a_1 = [1,2,3]
a_2 = [4,5,6]
a_3 = [7,8,9]
a10 = mat([a_1,a_2,a_3])
x = a10.sum(axis=0)
print('sum column is',x)
y = a10.sum(axis=1)
print('sum row is',y)
z = sum(a10[0,:])
print('sum first row is',z)
#最大值最小值
a11 = a10
a11_1 = a11.max()
a11_2 = max(a11[:,1])
a11_3 = np.max(a11 ,0)

最后一行是想要得到所有列的最大值

报错说:NameError: name 'np' is not defined

去掉“np”也是错的:ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

所以应该怎么办???

本文地址:https://blog.csdn.net/lz9797/article/details/107349935