下面这段代码是使用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”问题的解决的更多相关文章

  1. 谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching

    最近在学习Spring+SpringMVC+MyBatis,一个人的挖掘过程确实有点艰难,尤其是有一些神奇的报错让你会很蛋疼.特别是接触一些框架还是最新版本的时候,会因为版本问题出现很多错误,欢迎大家 ...

  2. http.Handler 与Go的错误处理

    原文地址    在之前我写过一篇关于通过使用http.HandlerFunc来实现一个定制handler类型用来避免一些平常的错误的文章.func MyHandler(w http.ResponseW ...

  3. Oracle linux6.1配置yum本地源

    一.准备工作1. Linux安装盘插入光驱2. 挂载光驱 [root@localhost ~]# mount /dev/cdrom /mnt/ mount: block device /dev/sr0 ...

  4. 【linux】yum本地源制作

    在/etc/yum.repos.d/ 目录下,有两个文件  CentOS-Base.repo和 CentOS-Media.repo 其中CentOS-Base.repo 记录着网络上的 yum 源的地 ...

  5. [HIve - LanguageManual] Hive Operators and User-Defined Functions (UDFs)

    Hive Operators and User-Defined Functions (UDFs) Hive Operators and User-Defined Functions (UDFs) Bu ...

  6. [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数

    Built-in Operators Relational Operators The following operators compare the passed operands and gene ...

  7. Hive之内置函数

    函数分类 UDF(User Defined Function):数据一对一 UDAF(User Defined Aggreation Function):数据多对一 UDTF(User Defined ...

  8. QC在win7下不能访问QC服务器介绍

    本地访问不了服务器QC的主要几个原因总结 服务器serverjbossextensionhpcmd 2016-03-24   兼容性问题: 1.在服务端QC的安装目录下jboss\server\def ...

  9. iOS支付宝集成时遇到的问题整理(1)

    1.模拟器上运行正常,但是真机调试时报编译链接错误 :ld: '/Users/wangqipeng/Desktop/iOS支付宝官方文档/AlixPayDemo/libcrypto.a(bio_lib ...

随机推荐

  1. 纪念我逝去的n个小时

    纪念我逝去的n个小时 某人的惨案要我擦屁股=.= #include <bits/stdc++.h> using namespace std; template<class T> ...

  2. CADisplayLink、NSTimer循环引用解决方案

    前言:CADisplayLink.NSTimer 循环引用问题 ​ CADisplayLink.NSTimer会对Target产生强引用,如果target又对他们产生强引用,那么就会引发循环引用. @ ...

  3. 笔记本USB接口案例分析和是实现

    笔记本电脑 笔记本电脑(laptop)通常具备使用USB设备的功能.在生产时,笔记本都预留了可以插入USB设备的USB接口,但具体是什么USB设备,笔记本厂商并不关心,只要符合USB规格的设备都可以 ...

  4. docker仓库之harbor的基本使用(二)

    1 1.配置docker使用harbor仓库上传下载镜像 2 #注意:如果我们配置的是https的话,本地docker就不需要任何操作就可以访问harbor 3 测试机器 4 root@ubuntu1 ...

  5. day01--DOS常用命令

    打开CMD的方式 开始+系统+命令提示符 Win键+R输入cmd打开控制台(推荐使用) 在任意的文件夹下面,按住shift键+鼠标右键点击,在此处打开命令行窗口 资源管理器的地址栏前面加,上cmd路径 ...

  6. Command 'ifconfig' not found, but can be installed with: sudo apt install net-tools解决方法

    VMware下安装的Ubuntu 当使用ifconfig命令查看网卡配置信息的时候出错 尝试了很多方法都解决不了,直到输入了下面的内容: 然后自己就更新了很多东西 之后重新输入ifconfig命令就能 ...

  7. springmvc异常处理解析#ExceptionHandlerExceptionResolver

    开头 试想一下我们一般怎么统一处理异常呢,答:切面.但抛开切面不讲,如果对每一个controller方法抛出的异常做专门处理,那么着实太费劲了,有没有更好的方法呢?当然有,就是本篇文章接下来要介绍的s ...

  8. mysql grant命令

    增删改查的权限grant select on testdb.* to common_user@'%' grant insert on testdb.* to common_user@'%' grant ...

  9. C#里如何简单的校验时间格式

    前言: 晚上打算睡觉的时候,群里反馈订单接收失败,开工排查问题,日志显示验签失败,发现一个蛮有意思的BUG,总算有了一个写作的素材 场景描述 本次的场景属于比较常见的收单API,对第三方的订单进行签名 ...

  10. mui 登录跳转到首页之后顶部选项卡不灵敏问题

    前段时间开发一个用mui开发app的时候遇到了登录跳转到首页之后顶部选项卡会失灵的问题,多次尝试之后终于解决了,趁现在还有点印象记录一下吧. 一开始我是用mui.openWindow来新开首页的,出了 ...