关于“No loop matching the specified signature and casting was found for ufunc lstsq_n”问题的解决
下面这段代码是使用MatPlotLib绘制数据随时间变化的趋势。
import datetime as dt
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.pylab as plb
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
df = pd.DataFrame(columns=('Time', 'Sales'))
start_date = dt.datetime(2022, 7, 1)
end_date = dt.datetime(2022, 7, 10)
daterange = pd.date_range(start_date, end_date)
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(15, 5))
for single_date in daterange:
row = dict(zip(['Time', 'Sales'], [single_date, int(50 * np.random.rand(1))]))
row_s = pd.Series(row)
row_s.name = single_date.strftime('%b %d')
df = df.append(row_s)
df.loc['Jul 01': 'Jul 07', ['Sales']].plot(ax=axes[0])
axes[0].set_ylim(0, 50)
axes[0].set_xlabel('Sales Date')
axes[0].set_ylabel('Sale Value')
axes[0].set_title('在轴上表示时间')
axes[0].grid()
# 标绘随时间的趋势
df.loc['Jul 01': 'Jul 07', ['Sales']].plot(ax=axes[1])
xx = np.arange(0, 10).flatten() * 1.0
yy = df['Sales'].values.flatten() * 1.0
# 下面的print用于调试,正式代码中或删除
print('xx: ', xx)
print('type(xx): ', type(xx))
print('type(xx[0]): ', type(xx[0]))
print('xx shape: ', xx.shape)
print('yy: ', yy)
print('type(yy): ', type(yy))
print('type(yy[0]): ', type(yy[0]))
print('yy shape: ', yy.shape)
# 上面的print用于调试,正式代码中或删除
z1 = np.polyfit(xx, yy, 1)
p1 = np.poly1d(z1)
plb.plot(xx, p1(xx), 'm-')
axes[1].set_ylim(0, 50)
axes[1].set_xlabel('Sales Date')
axes[1].set_ylabel('Sale Value')
axes[1].set_title('标绘随时间的趋势')
axes[1].legend(['Sales', 'Trend'])
axes[1].grid()
上面代码在最初运行时,并没有中间一大段print,当执行到z1 = np.polyfit(xx, yy, 1)时报错,在一大段错误信息最后,有一句“TypeError: No loop matching the specified signature and casting was found for ufunc lstsq_n” 。大致意思是:没有找到符合指定签名和特征的循环。
在查找原因的过程中,看到一篇文章pearsonr计算相关性时报错:No loop matching the specified signature and casting was found for ufunc add,其描述的错误现象和上面错误基本相同。于是尝试按照文章中的思路来解决,也才有了上面代码中大段的print。
注意到xx和yy不相同的地方是:xx中元素的类型是:numpy.float64,而yy中元素的类型是float,可能这就是产生错误的原因。于是生成yy的语句由原来的yy = df['Sales'].values.flatten() * 1.0,改为yy = np.array(df['Sales'].values * 1.0, dtype='float64').flatten(),再次运行后没有报错,并绘制出相应的图形。
关于“No loop matching the specified signature and casting was found for ufunc lstsq_n”问题的解决的更多相关文章
- 谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching
最近在学习Spring+SpringMVC+MyBatis,一个人的挖掘过程确实有点艰难,尤其是有一些神奇的报错让你会很蛋疼.特别是接触一些框架还是最新版本的时候,会因为版本问题出现很多错误,欢迎大家 ...
- http.Handler 与Go的错误处理
原文地址 在之前我写过一篇关于通过使用http.HandlerFunc来实现一个定制handler类型用来避免一些平常的错误的文章.func MyHandler(w http.ResponseW ...
- Oracle linux6.1配置yum本地源
一.准备工作1. Linux安装盘插入光驱2. 挂载光驱 [root@localhost ~]# mount /dev/cdrom /mnt/ mount: block device /dev/sr0 ...
- 【linux】yum本地源制作
在/etc/yum.repos.d/ 目录下,有两个文件 CentOS-Base.repo和 CentOS-Media.repo 其中CentOS-Base.repo 记录着网络上的 yum 源的地 ...
- [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)
Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...
- [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数
Built-in Operators Relational Operators The following operators compare the passed operands and gene ...
- Hive之内置函数
函数分类 UDF(User Defined Function):数据一对一 UDAF(User Defined Aggreation Function):数据多对一 UDTF(User Defined ...
- QC在win7下不能访问QC服务器介绍
本地访问不了服务器QC的主要几个原因总结 服务器serverjbossextensionhpcmd 2016-03-24 兼容性问题: 1.在服务端QC的安装目录下jboss\server\def ...
- iOS支付宝集成时遇到的问题整理(1)
1.模拟器上运行正常,但是真机调试时报编译链接错误 :ld: '/Users/wangqipeng/Desktop/iOS支付宝官方文档/AlixPayDemo/libcrypto.a(bio_lib ...
随机推荐
- Centos8安装NextCloud记录
今天在网上学习了这个Nextcloud 网盘的搭建,被折磨的快崩溃了.始终是找不到答案,我在网上查了2天的资料 还是没有找到答案,今天这里总结一下安装的下面的总结: 原文出处在官网:CentOS 8 ...
- 016(剪花布条)(KMP)
题目:http://ybt.ssoier.cn:8088/problem_show.php?pid=1465 题目思路:KMP模板题,该说的都在代码里 #include<bits/stdc++. ...
- # Vue3 setup 函数
Vue3 setup 函数 vue2 和 vue3 开发的区别 首先,目前来说 vue3 发布已经有一段时间了,但是呢,由于还处于优化完善阶段,对于 vue3 开发项目的需求不是很高,主要还是以 vu ...
- runc hang 导致 Kubernetes 节点 NotReady
Kubernetes 1.19.3 OS: CentOS 7.9.2009 Kernel: 5.4.94-1.el7.elrepo.x86_64 Docker: 20.10.6 先说结论,runc v ...
- Dapr v1.8 正式发布
Dapr是一套开源.可移植的事件驱动型运行时,允许开发人员轻松立足云端与边缘位置运行弹性.微服务.无状态以及有状态等应用程序类型.Dapr能够确保开发人员专注于编写业务逻辑,而不必分神于解决分布式系统 ...
- vue2升级vue3指南(一)—— 环境准备和构建篇
1.nodejs和npm 注意二者的版本,版本过低需要升级,本人升级后的版本如下: $ node -v v16.15.1 $ npm -v 8.11.0 2.package.json 和依赖升级 由于 ...
- kubernetes 调度
pod 分配给特定的node节点 目的:在一般业务场景,有些pod需要运行在特定的物理节点上,可以通过kubernetes的nodeSelector.nodeName安排pod到指定的节点上运行. # ...
- 用cmd命令进行磁盘清理(主要是系统盘)
作用:清理磁盘(主要是系统盘)中不需要的垃圾文件操作方法: 第一步:Windows键+R键 调出cmd命令窗口(窗口图如下:) 第二步:输入框中输入cmd命令,按下Enter键,进入如下图界面: 第三 ...
- C++学习记录1
代码1:转义字符 点击查看代码 #include<iostream> using namespace std; void test01()//换行 { cout << &quo ...
- Linux配置Oracle JAVA环境
1.下载java jdk的安装包 #pwd /usr/local/src 2.解压二进制文件并设置软连接 # tar -xvf jdk-8u241-linux-x64.tar.gz # ln -sv ...