我在magickwand和python和Mac OX X上遇到问题。
导入时出现错误:
ImportError: MagickWand shared library not found. You probably had not
installed ImageMagick library. Try to install: brew install imagemagick
Run Code Online (Sandbox Code Playgroud)
brew install imagemagick Warning: imagemagick-6.8.9-1 already installed
Run Code Online (Sandbox Code Playgroud) 例如,我想:
texta = text.lower()
textacopy1 = texta.replace(string.punctuation, ' ')
textacopy2 = textacopy1.split(' ')
Run Code Online (Sandbox Code Playgroud)
有没有更简洁的方法来做这个而不必分配多个变量?
如果2.7和3.x之间存在差异,我更倾向于3.x解释.
使用pandas和seaborn绘制只有三个点的散点图时会出现奇怪的行为:这些点的颜色不同.当没有加载seaborn或者有超过三个点时,或者直接用matplotlib的散射方法绘图时,问题就会消失.请参阅以下示例:
from pandas import DataFrame #0.16.0
import matplotlib.pyplot as plt #1.4.3
import seaborn as sns #0.5.1
import numpy as np #1.9.2
df = DataFrame({'x': np.random.uniform(0, 1, 3), 'y': np.random.uniform(0, 1, 3)})
df.plot(kind = 'scatter', x = 'x', y = 'y')
plt.show()
Run Code Online (Sandbox Code Playgroud)

df = DataFrame({'x': np.random.uniform(0, 1, 4), 'y': np.random.uniform(0, 1, 4)})
df.plot(kind = 'scatter', x = 'x', y = 'y')
plt.show()
Run Code Online (Sandbox Code Playgroud)

我有一些使用intel fortran编译器ifort编译的fortran代码.当我使用gprof进行配置文件测试时,我得到的大部分时间用于IO操作,我想找到文件的结尾,但我找不到更多关于此的文档:
index % time self children called name
<spontaneous>
[1] 20.6 0.07 0.00 _IO_wfile_seekoff [1]
-----------------------------------------------
<spontaneous>
[2] 20.6 0.07 0.00 sforcepf_ [2]
-----------------------------------------------
<spontaneous>
[3] 20.6 0.02 0.05 _IO_wfile_underflow [3]
0.01 0.04 258716/258717 strncmp [4]
-----------------------------------------------
0.00 0.00 1/258717 _IO_wdefault_doallocate [15]
0.01 0.04 258716/258717 _IO_wfile_underflow [3]
[4] 14.7 0.01 0.04 258717 strncmp [4]
0.04 0.00 3104592/3109256 strerror_r [5]
-----------------------------------------------
0.00 0.00 4664/3109256 __strcmp_sse42 [14]
0.04 0.00 3104592/3109256 strncmp [4]
[5] 11.8 0.04 0.00 3109256 strerror_r [5]
-----------------------------------------------
Run Code Online (Sandbox Code Playgroud)
那么,问题是,这个IO是针对Linux,还是针对ifort,还是针对fortran?我正在尝试优化此代码,并且在google中找不到有关此条款的有用信息.
我用filename创建了自己的模块mymodule.py。该文件包含:
def testmod():
print "test module success"
Run Code Online (Sandbox Code Playgroud)
我已将此文件放在 /Library/Python/2.7/site-packages/mymodule/mymodule.py
我还添加了一个__init__.py文件,这些文件已编译生成
__init__.pyc 和 mymodule.pyc
然后在python控制台中将其导入
import mymodule
哪个很好
当我尝试使用mymodule.testmod()时,出现以下错误:
AttributeError: 'module' object has no attribute 'testmod'
是的,它似乎没有任何功能?
在Python中,当您有一个对象时,可以使用该int函数将其转换为整数.
例如int(1.3)将返回1.__int__在这种特殊情况下,这通过使用对象的魔术方法在内部工作float.__int__.
在Python中,Fraction对象可用于构造精确的分数.
from fractions import Fraction
x = Fraction(4, 3)
Run Code Online (Sandbox Code Playgroud)
Fraction对象缺少一个__int__方法,但你仍然可以调用int()它们并获得一个合理的整数.我想知道如何在没有__int__定义方法的情况下实现这一点.
In [38]: x = Fraction(4, 3)
In [39]: int(x)
Out[39]: 1
Run Code Online (Sandbox Code Playgroud) 样本循环:
do i=1,1
print *,i
enddo
print *,i
Run Code Online (Sandbox Code Playgroud)
给了我2最终的价值i.我如何设置英特尔Fortran的Visual Studio在Windows上给我的最终价值1的i?
如果我有一个子图,如何更改其刻度数?我不知道数据的最大值和最小值。
我的代码是:
azal = rif.add_subplot(111)
azal.plot(eels*(10**9), averspe, label='data')
azal.plot(eels*(10**9), beck, label='fit')
azal.set_yscale('log')
azal.set_xscale('log')
h2 = azal.axvline(x = p2*(10**9), color='r')
azal.legend(bbox_to_anchor=(1.05, 1), loc=4, fontsize='xx-large', borderaxespad=0.)
rif.canvas.draw()
Run Code Online (Sandbox Code Playgroud) 我有一个像这样的熊猫数据框。
created_time reached_time
2016-01-02 12:57:44 14:20:22
2016-01-02 12:57:44 13:01:38
2016-01-03 10:38:51 12:24:07
2016-01-03 10:38:51 12:32:11
2016-01-03 10:38:52 12:23:20
2016-01-03 10:38:52 12:51:34
2016-01-03 10:38:52 12:53:33
2016-01-03 10:38:52 13:04:08
2016-01-03 10:38:52 13:13:40
Run Code Online (Sandbox Code Playgroud)
我想减去这两个日期列,并希望得到 time
我正在python中跟随
speed['created_time'].dt.time - speed['reached_time']
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误
TypeError: ufunc subtract cannot use operands with types dtype('O') and dtype('<m8[ns]')
的数据类型created_time是object与数据类型reached_typeIStimedelta64[ns]
我有一个列表,如:
[1,2,3,2,1,5,6]
Run Code Online (Sandbox Code Playgroud)
我想在列表中找到1的所有位置.我试过if语句,但我只获得前1的位置,而不是所有的1.
如果我使用if语句的实际输出[0],但预期的结果应该是[0,4].
python ×8
fortran ×2
pandas ×2
python-2.7 ×2
attributes ×1
axis-labels ×1
datetime ×1
fractions ×1
gprof ×1
imagemagick ×1
int ×1
list ×1
macos ×1
matplotlib ×1
module ×1
position ×1
python-3.x ×1
seaborn ×1
webapp2 ×1