我有以下问题.我想使用matplotlib包动画来保存mp4视频文件.save函数具有生成mp4文件(ffmpeg外部库)的依赖项.所以我通过Macports在Mac OSx 10.8上安装了ffmpeg,并安装了它/opt/local/bin.
但现在,在canopy中运行脚本,解释器(ipython shell)无法看到ffmpeg.我添加了.bash_profile的路径,我可以在我的终端上运行程序,但是当我键入时,我的shell os.environ['PATH']的实际PATH内容没有被添加,并且/opt/local/bin不存在.如果我尝试运行脚本,我会收到此错误:
/Users/alejandrodelacallenegro/Library/Enthought/Canopy_64bit/User/lib/python2.7/site- packages/matplotlib/animation.py:695: UserWarning: MovieWriter ffmpeg unavailable
warnings.warn("MovieWriter %s unavailable" % writer)
Run Code Online (Sandbox Code Playgroud)
有什么想法来解决这个问题吗?我需要做些什么来改变python在启动时看到的环境变量?有没有人有同样的问题?
谢谢.
python environment-variables enthought osx-mountain-lion canopy
我的代码如下所示:
from sklearn.datasets import load_svmlight_files
import numpy as np
perm1 =np.random.permutation(25000)
perm2 = np.random.permutation(25000)
X_tr, y_tr, X_te, y_te = load_svmlight_files(("dir/file.feat", "dir/file.feat"))
#randomly shuffle data
X_train = X_tr[perm1,:].toarray()[:,0:2000]
y_train = y_tr[perm1]>5 #turn into binary problem
Run Code Online (Sandbox Code Playgroud)
代码工作正常,直到这里,但当我尝试将另一个对象转换为数组时,我的程序返回内存错误.
码:
X_test = X_te[perm2,:].toarray()[:,0:2000]
Run Code Online (Sandbox Code Playgroud)
错误:
---------------------------------------------------------------------------
MemoryError Traceback (most recent call last)
<ipython-input-7-31f5e4f6b00c> in <module>()
----> 1 X_test = X_test.toarray()
C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\compressed.pyc in toarray(self, order, out)
788 def toarray(self, order=None, out=None):
789 """See the docstring for `spmatrix.toarray`."""
--> 790 return self.tocoo(copy=False).toarray(order=order, out=out)
791
792 ##############################################################
C:\Users\Asq\AppData\Local\Enthought\Canopy\User\lib\site-packages\scipy\sparse\coo.pyc …Run Code Online (Sandbox Code Playgroud) 我有一个文本文件,它是边缘列表文件。我知道如何读取文件(使用Canopy Enthought),但是我不知道如何获取有关所需图形的信息。
主要问题:是否可以使用networkx命令检测此图(从边缘列表文件创建)是有向的还是无向的?还是只是称重或称重?
我正在尝试使用以下代码:
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
import numpy as np
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
ImportError: No module named sklearn.datasets
Run Code Online (Sandbox Code Playgroud)
然后我尝试安装scikit-learn,但得到这些错误:
pip install -U scikit-learn
File "<ipython-input-9-6d283b29f0f9>", line 1
pip install -U scikit-learn
^
SyntaxError: invalid syntax
easy_install -U scikit-learn
File "<ipython-input-10-59440c1e5ef6>", line 1
easy_install -U scikit-learn
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
我正在使用Enthought Canopy Expresss,我认为"The Enthought Python Distribution已经发布了最新版本." 根据http://scikit-learn.org/stable/install.html#enthought-python-distribution
我该怎么用scikit-learn?
编辑:
pip通过easy_install pip我安装然后尝试运行pip install -U scikit-learn,我得到这些错误(从我的日志文件):
running build_clib
No module …Run Code Online (Sandbox Code Playgroud) 我现在运行Enthought Canopy 1.4.1 64位一年.出于某种原因,我刚刚编写的代码在按下"播放"按钮时生成完全不同的图表(使用matplotlib),而不是将代码复制并粘贴到命令行并按Enter键.
特别是,以下行产生两种不同的结果:
w1 = array(dot(matrix(C).I,R - 0.03)/sum(dot(matrix(C).I,R - 0.03)))[0]
按下Play时,我得到:
w1
Out[7]: array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
Run Code Online (Sandbox Code Playgroud)
复制并粘贴完全相同的代码并按Enter键时,我得到:
w1
Out[9]:
array([-0.53497564, 0.77325699, 0.3289724 , 0.2127899 , 0.29026341,
0.18743744, -0.24510907, -0.1117449 , -0.2534066 , 0.15694775,
0.19556833])
Run Code Online (Sandbox Code Playgroud)
我认为这是弄乱我的图表的,有谁知道为什么会发生这种情况?
Hy ...我只是在学习python.我做了一个这样的程序:
guess = raw_input("please input something...");
while (guess != 'h'):
guess = raw_input("pleae input something again....");
print(guess);
print("Thanks...");
Run Code Online (Sandbox Code Playgroud)
嗯......上面的程序运行良好.但是当我在猜测后输入"OR"时!='h'就像这样:
guess = raw_input("please input something...");
while (guess != 'h') or (guess != 't'):
guess = raw_input("pleae input something again....");
print(guess);
print("Thanks...");
Run Code Online (Sandbox Code Playgroud)
以上程序在while循环中永远运行.那里发生了什么?我认为在输入h或t后循环将结束