关于“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 ...
随机推荐
- VScode中配置Java环境
vscode 中配置Java环境 转载说明:本篇文档原作者[@火星动力猿],文档出处来自哔哩哔哩-[教程]VScode中配置Java运行环境 转载请在开头或显眼位置标注转载信息. 1.下载VScode ...
- CVPR 2017:See the Forest for the Trees: Joint Spatial and Temporal Recurrent Neural Networks for Video-based Person Re-identification
[1] Z. Zhou, Y. Huang, W. Wang, L. Wang, T. Tan, Ieee, See the Forest for the Trees: Joint Spatial a ...
- HashSet底层HashMap源码分析
在看HashSet源码的时候,意外发现底层HashMap保存的value居然不是null,而是保存一个Object作为Value.顿觉有悖常理,于是来分析一下: HashSet的add方法: publ ...
- 是时候优雅的和NullPointException说再见了
是时候优雅的和NullPointException说再见了 ️️️️️️️️️️️️️️️️ 最近在参加原创投稿比赛,本篇文章如果对你有帮助的话,欢迎帮忙点击助力下吧 NullPointExcepti ...
- Solution -「2020.12.26」 模拟赛
0x00 前言 一些吐槽. 考得很变态诶,看每道题平均两秒的时限就知道了... T1 降智了想到后缀懒得打. T2 口胡了假优化,结果和暴力分一样?? T3 黑题还绑点?? \(50 + 80 + 0 ...
- jdbc 09: preparedStatement实现增删改查
jdbc连接mysql,利用preparedStatement实现增删改查 package com.examples.jdbc.o9_preparedStatement实现增删改; import ja ...
- 中高级Java程序员,挑战20k+,知识点汇总(一),Java修饰符
1 前言 工作久了就会发现,基础知识忘得差不多了.为了复习下基础的知识,同时为以后找工作做准备,这里简单总结一些常见的可能会被问到的问题. 2 自我介绍 自己根据实际情况发挥就行 3 Java SE ...
- Odoo14 给模块/应用加小图标
# apps中的图标是固定路劲: static/description/icon.png # 主页图标是通过你的主menuitem的web_icon来设置的: <menuitem id=&quo ...
- python的嵌入式开发
今天晚上注定我要玩一夜这个东西,太爽了,给力! 烧写固件成功, http://blog.csdn.net/Lingdongtianxia/article/details/78248888 要点总结:如 ...
- Hammersley采样类定义和测试
原理参照书籍 类声明: #pragma once #ifndef __HAMMERSLEY_HEADER__ #define __HAMMERSLEY_HEADER__ #include " ...