下面这段代码是使用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. 动态树 — Link_Cut_Tree

    [模板]动态树(Link Cut Tree) Link-cut-tree是一种维护动态森林的数据结构,在需要动态加边/删边的时候就需要LCT来维护. Link-cut-tree的核心是轻重链划分,每条 ...

  2. 强化学习-学习笔记4 | Actor-Critic

    Actor-Critic 是价值学习和策略学习的结合.Actor 是策略网络,用来控制agent运动,可以看做是运动员.Critic 是价值网络,用来给动作打分,像是裁判. 4. Actor-Crit ...

  3. ReentrantLock 公平锁源码 第1篇

    ReentrantLock 1 这篇还是接着ReentrantLock的公平锁,没看过第0篇的可以先去看上一篇https://www.cnblogs.com/sunankang/p/16456342. ...

  4. MongoDB慢查询与索引

    MongoDB慢查询 慢查询分析 开启内置的慢查询分析器 db.setProfilingLevel(n,m),n的取值可选0,1,2 0:表示不记录 1:表示记录慢速操作,如果值为1,m需要传慢查询的 ...

  5. SkyWalking分布式系统应用程序性能监控工具-上

    概述 微服务系统监控三要素 现在系统基本都是微服务架构,对于复杂微服务链路调用如下问题如何解决? 一个请求经过了这些服务后其中出现了一个调用失败的问题,如何定位问题发生的地方? 如何计算每个节点访问流 ...

  6. 栈和排序_via牛客网

    题目 链接:https://ac.nowcoder.com/acm/contest/26886/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...

  7. 「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader

    「游戏引擎 浅入浅出」从零编写游戏引擎教程,是一本开源电子书,PDF/随书代码/资源下载: https://github.com/ThisisGame/cpp-game-engine-book 4.1 ...

  8. HashSet集合存储数据的结构(哈希表)和Set集合存储㢝不重复的原理

    HashSet集合存储数据的结构(哈希表) Set集合存储㢝不重复的原理 前提:存储的元素必须重写hashCode方法和equals方法

  9. 清北学堂 2020 国庆J2考前综合强化 Day4

    目录 1. 题目 T1 写字符串 题目描述 Sol T2 神奇的数 题目描述 Sol T3 珠子染色 题目描述 Sol T4 病毒扩散 题目描述 Sol 算法 -- 图论 1. 题目 T1 写字符串 ...

  10. php apache 和mysql查看版本常用方法收集

    php: 1.命令行查询,下图是因为添加php进系统环境变量了 2.预定义常量PHP_VERSION查询 3.phpversion()函数查询 4.phpinfo()查询 apache: mysql: ...