GVKun编程网logo

如何使用 numpy 和 scipy 更改异常值(numpy改变数据类型)

5

对于如何使用numpy和scipy更改异常值感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍numpy改变数据类型,并为您提供关于centosinstallscipy问题:File"scipy/

对于如何使用 numpy 和 scipy 更改异常值感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍numpy改变数据类型,并为您提供关于centos install scipy 问题:File "scipy/linalg/setup.py", line 20, in configuration raise NotFoundE、Centos7安装python3、numpy、scipy、matplotlib、pandas等、matplotlib numpy scipy 的安装、Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack的有用信息。

本文目录一览:

如何使用 numpy 和 scipy 更改异常值(numpy改变数据类型)

如何使用 numpy 和 scipy 更改异常值(numpy改变数据类型)

如何解决如何使用 numpy 和 scipy 更改异常值

我正在尝试使用 numpy(不使用 Pandas)删除异常值。 我创建了一个如下所示的数组:

  1. [[-9.00681170e-01 1.01900435e+00 -1.34022653e+00 -1.31544430e+00]
  2. [-1.14301691e+00 -1.31979479e-01 -1.34022653e+00 -1.31544430e+00]
  3. [-1.38535265e+00 3.28414053e-01 -1.39706395e+00 -1.31544430e+00]
  4. [-1.50652052e+00 9.82172869e-02 -1.28338910e+00 -1.31544430e+00]
  5. [-1.02184904e+00 1.24920112e+00 -1.34022653e+00 -1.31544430e+00]
  6. [-5.37177559e-01 1.93979142e+00 -1.16971425e+00 -1.05217993e+00]
  7. [-1.50652052e+00 7.88807586e-01 -1.34022653e+00 -1.18381211e+00]
  8. [-1.02184904e+00 7.88807586e-01 -1.28338910e+00 -1.31544430e+00]]

我想创建一个函数来检查该数组,如果它找到任何数字: x>=3 它将用 2.9 替换它 如果它找到一个 x

  1. def ignoreOutlieres(array):
  2. for i in array:
  3. for x in i:
  4. x = float(format(x,".2f"))
  5. if x >= 3:
  6. x = 2.99
  7. elif x <= -3:
  8. x = -2.99
  9. return array

但是我遇到了这个类型错误:

TypeError: ''float'' 对象不能被解释为整数

然后我尝试使用 numpt 和 z 测试:

  1. def ignoreOutlieres(num_array):
  2. for i in num_array:
  3. i = np.all(stats.zscore(i)>=3,axis = 2.9)
  4. return num_array

但我认为我并没有真正理解它背后的想法,而且我没有正确使用它。 不适用于任何形式的帮助或指导。 我想最终得到的输出看起来像这样:

  1. [[-0.90068117,1.01900435,-1.34022653,-1.3154443 ],[-1.14301691,-0.13197948,[-1.38535265,0.32841405,-1.39706395,[-1.50652052,0.09821729,-1.2833891,[-1.02184904,1.24920112,[-0.53717756,1.93979142,-1.16971425,-1.05217993],0.78880759,-1.18381211],[-1.74885626,-0.36217625,-1.44707648],1.47939788,[-1.26418478,-1.22655167,[-1.87002413,-1.51073881,[-0.05250608,2.16998818,-1.45390138,[-0.17367395,2.9,[-0.90068117,1.70959465,-1.18381211]])

解决方法

在使用 numpy 时不应该使用循环。您需要 np.where,它是 numpy 的 forif 的组合等价物:

  1. patched = np.where(array <= -3,-2.99,np.where(array >= 3,2.99,array))
,

您可以使用 numpy 的索引来更改这些值。 numpy_array >= 3 返回一个布尔数组,因此 numpy_array[numpy_array >= 3] = 2.99 替换 numpy_array >= 3 计算结果为 True2.99 的每个位置。

  1. def change_outliers(numpy_array):
  2. numpy_array[numpy_array >= 3] = 2.99
  3. numpy_array[numpy_array <= -3] = -2.99
  4. return numpy_array

centos install scipy 问题:File

centos install scipy 问题:File "scipy/linalg/setup.py", line 20, in configuration raise NotFoundE

依赖包: pyparsing、dateutil、scipy、numpy、libpng 1.2 (or later)、`freetype` 1.4 (or later) 安装pyparsing: # pip install pyparsing 安装numpy: # pip install numpy 安装dateutil: # pip install python-dateutil 安装scipy: # pip install scipy 待测:sudo yum -y install gcc gcc-c++ numpy python-devel scipy(不过这些包都装好了) 报错: # pip install scipy Downloading/unpacking scipy Downloading scipy-0.17.1.tar.gz (12.4MB): 81kB downloaded Exception: Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py",line 139,in main status = self.run(options,args) File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/commands/install.py",line 266,in run requirement_set.prepare_files(finder,force_root_egg_info=self.bundle,bundle=self.bundle) File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py",line 1033,in prepare_files self.unpack_url(url,location,self.is_download) File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py",line 1161,in unpack_url retval = unpack_http_url(link,self.download_cache,self.download_dir) File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/download.py",line 554,in unpack_http_url download_hash = _download_url(resp,link,temp_location) File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/download.py",line 458,in _download_url chunk = resp.read(4096) File "/usr/local/lib/python2.7/socket.py",line 380,in read data = self._sock.recv(left) File "/usr/local/lib/python2.7/httplib.py",line 567,in read s = self.fp.read(amt) File "/usr/local/lib/python2.7/socket.py",in read data = self._sock.recv(left) File "/usr/local/lib/python2.7/ssl.py",line 246,in recv return self.read(buflen) File "/usr/local/lib/python2.7/ssl.py",line 165,in read return self._sslobj.read(len) SSLError: The read operation timed out Storing complete log in /root/.pip/pip.log 解决方法: # pip --default-timeout=100 install django 重新安装scipy 各个安装包版本: nose-1.3.1 lapack-3.5.0 atlas-3.10.1 scipy-0.11.0 numpy-1.6.2 依赖关系:scipy的安装需要依赖于numpy、lapack、atlas(后两者都是线性代数工具包,不清楚的自行google),而numpy和sci的测试程序的运行又依赖于nose,因此,整个安装过程必须要按顺序执行的,否则是无法执行下去的。 安装nose: # pip install nose 安装lapack: #yum install lapack lapack-devel blas blas-devel 更新pip # pip install --upgrade pip 安装scipy: # pip install scipy 安装matplotlib: # pip install matplotlib 报错: 安装freetype: 依赖freetype-devel # yum install freetype-devel # yum install freetype 安装matplotlib: # cd matplotlib-1.5.1 # python setup.py install 测试: 参考:http://paperman825.blog.chinaunix.NET/uid-25691489-id-5602653.html

Centos7安装python3、numpy、scipy、matplotlib、pandas等

Centos7安装python3、numpy、scipy、matplotlib、pandas等

centos 7 已经自带 python 2.7.15,这里需要安装 python 3

[root@pwm]# python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2

第一步:安装依赖包

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

 

第二步:下载python 3,这里下载 3.8.5

https://www.python.org/downloads/source/

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz

 

第三步:指定存放目录(/usr/local/python3就是python3的安装目录)

mkdir /usr/local/python3

 

第四步:解压压缩包,进入该目录

tar -xvJf  Python-3.8.5.tar.xz
cd Python-3.8.5
./configure --prefix=/usr/local/python3

(注:./configure --prefix=/usr/local/python3这句的作用就是将程序安装在/usr/local/python3这个目录下)

 

第五步:安装python3

make && make install

(注:make是编译,make install是安装)

 

第六步:创建软链接(将 /usr/bin/python3指向/usr/local/python3/bin/python3)

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

 

升级pip(如果需要)

按照提示升级pip,命令:pip3 install --upgrade pip

 

使用:

/usr/local/python3/bin/python3

 

 

2.安装其它(直接输入命令)

pip3 install numpy

pip3 install scipy

pip3 install matplotlib

pip3 install pandas

pip3 install statsmodels

pip3 install scikit-learn

pip3 install gensim

pip3 install theano

pip3 install keras

pip3 install tensorflow

 

 

REF

https://www.cnblogs.com/zhangtingzu/p/8650664.html

centos 7 已经自带 python 2.7.15,这里需要安装 python 3

[root@pwm]# python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2

第一步:安装依赖包

yum -y groupinstall "Development tools"

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

 

第二步:下载python 3,这里下载 3.8.5

https://www.python.org/downloads/source/

wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz

 

第三步:指定存放目录(/usr/local/python3就是python3的安装目录)

mkdir /usr/local/python3

 

第四步:解压压缩包,进入该目录

tar -xvJf  Python-3.8.5.tar.xz
cd Python-3.8.5
./configure --prefix=/usr/local/python3

(注:./configure --prefix=/usr/local/python3这句的作用就是将程序安装在/usr/local/python3这个目录下)

 

第五步:安装python3

make && make install

(注:make是编译,make install是安装)

 

第六步:创建软链接(将 /usr/bin/python3指向/usr/local/python3/bin/python3)

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

 

升级pip(如果需要)

按照提示升级pip,命令:pip3 install --upgrade pip

 

使用:

/usr/local/python3/bin/python3

 

 

2.安装其它(直接输入命令)

pip3 install numpy

pip3 install scipy

pip3 install matplotlib

pip3 install pandas

pip3 install statsmodels

pip3 install scikit-learn

pip3 install gensim

pip3 install theano

pip3 install keras

pip3 install tensorflow

 

 

REF

https://www.cnblogs.com/zhangtingzu/p/8650664.html

matplotlib numpy scipy 的安装

matplotlib numpy scipy 的安装

 

 

一:windows 端的安装

#cmd指令
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

 成功安装所需库!

 

二、linux端安装--基于Ubuntu的操作

第一步:下载压缩包到指定位置

jiyongjia@ubuntu:~$ cd ~/Downloads/

jiyongjia@ubuntu:~/Downloads$ wget https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.4.3/matplotlib-1.4.3.tar.gz

 

第二步:解压下载的压缩包

jiyongjia@ubuntu:~/Downloads$ tar xzf matplotlib-1.4.3.tar.gz
jiyongjia@ubuntu:~/Downloads$ cd matplotlib-1.4.3/
jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ ls

第三步:进入文件夹进行编译

jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ python3 setup.py build

第四步:安装

jiyongjia@ubuntu:~/Downloads/matplotlib-1.4.3$ python3 setup.py install

 



Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

如何解决Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack

我在matplotlib和scipy之间的交互方面遇到一些问题。 这是我对情况的理解:

  1. 错误在于LinearRegression的{​​{1}}抛出sklearn
  2. 经过一些调试后,SVD not converging error引发了错误,其中scipy\\linalg\\basic.py方法返回的信息值不同于dgesld(在这种情况下为0)。在我的情况下,使用的-4是fortran flatpack lapack_func
  3. 错误似乎取决于输入的数字和dgesldpyplot)代码,尤其是方法matplotlibyticks
  4. 该错误首先发生在多线性回归问题中(xticks中的信息值等于23,在这种情况下为正值),但我编写了以下脚本来更好地概述问题
  1. scipy\\linalg\\basic.py

在具有以下功能的Windows 10计算机上运行时:

  1. import numpy as np
  2. from sklearn.linear_model import LinearRegression
  3. import matplotlib.pyplot as plt
  4. a = [0.27236845,0.79433854,0.05986454,0.62736383,0.5732594,0.54175392,0.92359127,0.19913404,0.17357701,0.10225879,0.94727807,0.23766063,0.92438574,0.10981865,0.18669187,0.71337215,0.17843819,0.98693265,0.80787247,0.931572]
  5. b = [1.68869178,2.20448291,1.64828788,1.95276497,1.23976119,1.61260175,1.32652345,1.94535222,1.37353248,1.47830833,1.08400723,1.91091901,1.63909271,2.37494003,1.64490261,1.90403079,1.81028796,1.66986048,1.65304452,1.60747378]
  6. for no_plot in [True,False]:
  7. for i in range(len(a)-1):
  8. _a = a[:i + 2]
  9. _b = b[:i + 2]
  10. if not no_plot:
  11. bar_color = "blue"
  12. margin = 10
  13. y_label = x_label = None
  14. angle = 0
  15. title = "TestError"
  16. color_theme = (0 / 235,32 / 235,96 / 235)
  17. fig,ax = plt.subplots(figsize=(18,6.8))
  18. plt.bar(_a,_b,color=bar_color)
  19. Box = ax.get_position()
  20. ax.set_position([Box.x0,Box.y0 + margin * Box.height,Box.width,Box.height * (1 - margin)])
  21. plt.xticks(fontname="Cambria",color=color_theme,rotation=angle,fontsize=25)
  22. plt.yticks(fontname="Cambria",fontsize=25)
  23. plt.title(title,fontname="Cambria",fontsize=25)
  24. ax_output = plt.gca()
  25. try:
  26. reg = LinearRegression().fit(np.array(_a).reshape(-1,1),_b)
  27. print("Success: {},@ i={} with no_plot={}".format(reg.score(np.array(_a).reshape(-1,_b),i,no_plot))
  28. except Exception as e:
  29. print("Exception: {} @ i={} with no_plot={}".format(repr(e),no_plot))

python version: 3.7.9 scipy version: 1.5.2 scikit-learn version: 0.23.2 numpy version: 1.19.2 matplotlib version: 3.3.2

结果如下:

  1. _flapack.cp37-win_amd64

就堆栈跟踪而言:

  1. Success: 1.0,@ i=0 with no_plot=True
  2. Success: 0.9524690407545247,@ i=1 with no_plot=True
  3. Success: 0.9248909415334777,@ i=2 with no_plot=True
  4. Success: 0.17921330631542143,@ i=3 with no_plot=True
  5. Success: 0.1559357435898613,@ i=4 with no_plot=True
  6. Success: 0.001129573837944875,@ i=5 with no_plot=True
  7. Success: 0.008667658302087822,@ i=6 with no_plot=True
  8. Success: 0.001674117195053615,@ i=7 with no_plot=True
  9. Success: 0.011802146118754298,@ i=8 with no_plot=True
  10. Success: 0.024141340568111902,@ i=9 with no_plot=True
  11. Success: 0.04144995409093344,@ i=10 with no_plot=True
  12. Success: 0.03301917468171267,@ i=11 with no_plot=True
  13. Success: 0.0959782634092683,@ i=12 with no_plot=True
  14. Success: 0.08847483030078473,@ i=13 with no_plot=True
  15. Success: 0.06428117850391502,@ i=14 with no_plot=True
  16. Success: 0.07033033186821203,@ i=15 with no_plot=True
  17. Success: 0.06394158828230323,@ i=16 with no_plot=True
  18. Success: 0.0640239869160919,@ i=17 with no_plot=True
  19. Success: 0.06734590831873866,@ i=18 with no_plot=True
  20. Success: 1.0,@ i=0 with no_plot=False
  21. Success: 0.9524690407545247,@ i=1 with no_plot=False
  22. Success: 0.9248909415334777,@ i=2 with no_plot=False
  23. Success: 0.17921330631542143,@ i=3 with no_plot=False
  24. Success: 0.1559357435898613,@ i=4 with no_plot=False
  25. Success: 0.001129573837944875,@ i=5 with no_plot=False
  26. Success: 0.008667658302087822,@ i=6 with no_plot=False
  27. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=7 with no_plot=False
  28. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=8 with no_plot=False
  29. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=9 with no_plot=False<
  30. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=10 with no_plot=False
  31. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=11 with no_plot=False
  32. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=12 with no_plot=False
  33. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=13 with no_plot=False
  34. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=14 with no_plot=False
  35. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=15 with no_plot=False
  36. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=16 with no_plot=False
  37. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=17 with no_plot=False
  38. Exception: ValueError(''illegal value in 4-th argument of internal None'') @ i=18 with no_plot=False

坦白说,我有点迷路了。有人对此事有想法吗?

我们今天的关于如何使用 numpy 和 scipy 更改异常值numpy改变数据类型的分享已经告一段落,感谢您的关注,如果您想了解更多关于centos install scipy 问题:File "scipy/linalg/setup.py", line 20, in configuration raise NotFoundE、Centos7安装python3、numpy、scipy、matplotlib、pandas等、matplotlib numpy scipy 的安装、Matplotlib-Scipy / Sklearn交互-scipy.linalg._flapack的相关信息,请在本站查询。

本文标签: