本人出现的问题是,两个数组A,B的大小分别为(3000,20) (20,20), 是<numpy.ndarray>类型,而不是<matrix>类型,直接进行乘积C = A*B, 之后,提示上述错误,原因是数组大小“不一致”, 解决方案,不用"*"符号,使用numpy中的dot()函数,可以实现两个二维数组的乘积,或者将数组类型转化为矩阵类型,使用"*"相乘,具体如下:

[python] view plaincopy
  1. A = numpy.array([1,2], [3,4], [5,6])    # 3*2 numpy.ndarray
  2. B = numpy.array([1,2,3], [4,5,6])       # 2*3 numpy.ndarray
  3. C = A * B    # raise error: ValueError: operands could not be broadcast together with shapes (3,2) (2,2)
  4. # solution method 1
  5. C = numpy.dot(A, B)             # C: 3*3 numpy.ndarray
  6. # solution method 2
  7. A_mat = numpy.matrix(A)
  8. B_mat = numpy.matrix(B)
  9. C = A_mat * B_mat           # C: 3*3 numpy.matrixlib.defmatrix.matrix

ValueError: operands could not be broadcast together with shapes (3000,20) (20,20)相关推荐

  1. ValueError: operands could not be broadcast together with shapes解决

    ValueError: operands could not be broadcast together with shapes (1,2) (1,3) import numpy as np a=np ...

  2. 【python问题系列--4】ValueError: operands could not be broadcast together with shapes (100,3) (3,1)...

    背景:dataMatrix是(100,3)的列表,labelMat是(1,100)的列表,weights是(3,1)的数组,属性如下代码所示: >>> import types &g ...

  3. ValueError: operands could not be broadcast together with shapes (320,320,4) (3,) (320,320,4)

    problem: ValueError: operands could not be broadcast together with shapes (320,320,4) (3,) (320,320, ...

  4. 报错ValueError: operands could not be broadcast together with shapes (448,448) with (224,224)

    这个错误发生原因是因为图片的尺寸与weight 不匹配,不能做乘积,所以需要改变图片尺寸. 使用如下代码:img = cv2.resize(img, (448, 448)) 加在img = cv2.r ...

  5. operands could not be broadcast together with remapped shapes

    operands could not be broadcast together with remapped shapes 报错代码: point_num = 12try:labels=np.pad( ...

  6. einsum() operands do not broadcast with remapped shapes [original->remapped]报错解决方法

    RuntimeError: einsum() operands do not broadcast with remapped shapes [original->remapped]: [4, 6 ...

  7. 成功解决IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (100,)

    成功解决IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (100,) 目 ...

  8. multiply函数实例

    第一次在csdn写东西,好激动. 看到了multiply,本人一般都不读用户手册,都是自己试几个,基本上就够用了.(2020.09.29注:这TM什么坏习惯!!) (欢迎转载,标明出处,欢迎交流) - ...

  9. 【Python学习记录】Numpy广播机制(broadcast)

    ✨ 博客主页:小小马车夫的主页 ✨ 所属专栏:Python学习记录 文章目录 一.什么是Numpy广播机制 二.Numpy广播应用 三.Numpy广播规则 一.什么是Numpy广播机制 在Numpy. ...

  10. Numpy 广播机制(两个不同维度对象进行数学运算)

    1. 数组相加 一个 2*5 维的数组对象和一个 1 维的数组对象进行相加,结果会怎样? In [1]: import numpy as npIn [2]: a = np.arange(10).res ...

最新文章

  1. 在虚拟中开启Windows 8.1的Hyper-V平台
  2. Savitzky-Golay 滤波器详解及C/matlab语言程序设计
  3. 用Java解析:您可以使用的所有工具和库
  4. oracle中时间加减一年的写法
  5. POJ--3974 Palindrome(回文串,hash)
  6. 大数据可视化案例分析_Tableau数据可视化分析案例
  7. python中关于命名的例子_Python()-类命名空间和对象/实例命名空间
  8. 2019-07-18
  9. Python入门--字典元素的遍历for-in
  10. 2021-08-08备份数据库
  11. Rust : CSV库的用法
  12. 对话《哥德尔、埃舍尔、巴赫:集异璧之大成》作者:现在的AI还不够看
  13. CCF推荐期刊会议(A类)
  14. 【程序】Xilinx FPGA将DDR3内存转换为W25Q256的SPI接口,供STM32单片机调用,产生容量为256MB的USB U盘设备
  15. 声纹识别之Alize入门教程(四):matlab代码读取Spro工具提取的mfcc特征
  16. Win11封杀盗版office!不用找新密钥,这200套全行业终极模板够你用一辈子,一会儿删...
  17. 3208点阵时钟c语言程序,点阵万年历(带时间、年月日星期调整及闹钟功能)C程序...
  18. 华为Mate40Pro和华为Mate40Pro+ 哪个好
  19. 傻子,疯子,一根筋的人才能创业成功!
  20. 刷脸支付行业代理的几个坑,你踩了吗?

热门文章

  1. 用CALayer实现下载进度条
  2. 常用方法总结--文件操作篇
  3. IntelliJ IDEA多项目共用一个Tomcat
  4. Mybatis mapper.xml中常用标签详解
  5. Java中swing使用ImageIcon类添加图片
  6. 谢旭升《操作系统教程》课后习题解答
  7. linux常用命令全集sed,Linux常用命令之find详解
  8. 【前端】相信你会用到的一篇笔记---HTML篇
  9. java可不可以写挂_用Java怎么写呀???我怕是java要挂了,太艰难了
  10. 大型企业用什么orm_企业信息化系统建设的方案有什么用?