Questions tagged «python»

Python是一种多范式,动态类型的多用途编程语言。它旨在快速学习,理解和使用并强制使用干净统一的语法。请注意,Python 2自2020年1月1日起已不再受支持。不过,对于特定于版本的Python问题,请添加[python-2.7]或[python-3.x]标签。使用Python变体或库(例如Jython,PyPy,Pandas,Numpy)时,请将其包含在标签中。

3
numpy.exp()到底是做什么的?[关闭]
关闭。此问题不符合堆栈溢出准则。它当前不接受答案。 想改善这个问题吗?更新问题,使其成为Stack Overflow的主题。 5年前关闭。 改善这个问题 我对np.exp()的实际用途感到非常困惑。在文档中它说:“计算输入数组中所有元素的指数。” 我对这到底意味着什么感到困惑。有人能给我更多信息吗?
83 python  numpy  statistics  exp 

13
python中的功能管道,例如R的magritrr中的%>%
在R中(感谢magritrr),您现在可以通过通过更实用的管道语法执行操作%>%。这意味着无需编码: > as.Date("2014-01-01") > as.character((sqrt(12)^2) 您也可以这样做: > "2014-01-01" %>% as.Date > 12 %>% sqrt %>% .^2 %>% as.character 对我来说,这更具可读性,并且扩展到数据框之外的用例。python语言是否支持类似功能?


3
Django-从POST请求中获取值
我有以下django模板(将http:// IP / admin / start /分配给名为view的假设视图): {% for source in sources %} <tr> <td>{{ source }}</td> <td> <form action="/admin/start/" method="post"> {% csrf_token %} <input type="hidden" name="{{ source.title }}"> <input type="submit" value="Start" class="btn btn-primary"> </form> </td> </tr> {% endfor %} sources是objects.all()视图中引用的Django模型的。每当单击“开始”提交输入时,我都希望“开始”视图{{ source.title}}在返回渲染页面之前使用函数中的数据。如何将POST(在这种情况下,在隐藏的输入中)发布的信息收集到Python变量中?
83 python  django  post 

7
Python脚本通过FTP上传文件
我想编写一个脚本将文件上传到FTP。 登录系统将如何工作?我正在寻找这样的东西: ftp.login=(mylogin) ftp.pass=(mypass) 以及任何其他登录凭据。
83 python  ftp  upload 

11
是否需要range(len(a))?
人们经常在SO上的python问题中找到这种类型的表达式。只是访问可迭代的所有项目 for i in range(len(a)): print(a[i]) 这只是一种难以理解的写作方式: for e in a: print(e) 或分配给可迭代的元素: for i in range(len(a)): a[i] = a[i] * 2 哪个应该和: for i, e in enumerate(a): a[i] = e * 2 # Or if it isn't too expensive to create a new iterable a = [e * 2 …
83 python  for-loop  range 


3
“ i”在Python .pyi扩展名中代表什么?
在Python中,“。i”扩展名中的“ i”代表什么? 在PEP-484中,它提到.pyi是“存根文件”,但扩展名上没有助记符。那么“ i”是指“包含”吗?“实施”?“接口”?
83 python 


4
如何为散点图制作动画?
我正在尝试制作散点图的动画,其中点的颜色和大小在动画的不同阶段会发生变化。对于数据,我有两个带有x值和y值的numpy ndarray: data.shape = (ntime, npoint) x.shape = (npoint) y.shape = (npoint) 现在我想绘制一个散点图 pylab.scatter(x,y,c=data[i,:]) 并在索引上创建动画i。我该怎么做呢?



11
内置Python hash()函数
Windows XP,Python 2.5: hash('http://stackoverflow.com') Result: 1934711907 Google App Engine(http://shell.appspot.com/): hash('http://stackoverflow.com') Result: -5768830964305142685 这是为什么?我如何拥有一个散列函数,以便在不同平台(Windows,Linux,Mac)上给我相同的结果?

2
numpy如何比我的Fortran例程快得多?
我从仿真中得到了一个代表温度分布的512 ^ 3数组(用Fortran编写)。该阵列存储在大小约为1 / 2G的二进制文件中。我需要知道此数组的最小值,最大值和均值,并且由于不久以后无论如何我都需要了解Fortran代码,因此我决定尝试一下,并提出了以下非常简单的例程。 integer gridsize,unit,j real mini,maxi double precision mean gridsize=512 unit=40 open(unit=unit,file='T.out',status='old',access='stream',& form='unformatted',action='read') read(unit=unit) tmp mini=tmp maxi=tmp mean=tmp do j=2,gridsize**3 read(unit=unit) tmp if(tmp>maxi)then maxi=tmp elseif(tmp<mini)then mini=tmp end if mean=mean+tmp end do mean=mean/gridsize**3 close(unit=unit) 我使用的计算机上的每个文件大约需要25秒。那让我感到震惊,因为它相当长,所以我继续使用Python进行了以下操作: import numpy mmap=numpy.memmap('T.out',dtype='float32',mode='r',offset=4,\ shape=(512,512,512),order='F') mini=numpy.amin(mmap) maxi=numpy.amax(mmap) mean=numpy.mean(mmap) 现在,我希望这当然会更快,但是我真的很震惊。在相同条件下,它花费不到一秒钟的时间。平均值偏离了我的Fortran例程找到的平均值(我也使用128位浮点数运行,因此我以某种方式信任它),但仅在第7个有效位数左右。 numpy怎么这么快?我的意思是,您必须查看数组的每个条目才能找到这些值,对吗?我是否在Fortran例程中做了一些非常愚蠢的事情,以使其花费了更长的时间? 编辑: 要回答评论中的问题: 是的,我也使用32位和64位浮点数运行了Fortran例程,但它对性能没有影响。 我使用iso_fortran_env了提供128位浮点数的代码。 …

9
是什么引起ImportError:在OS X上升级Python之后,没有名为pkg_resources的模块?
我刚刚在Mac上将Python更新为2.6.4。我是从dmg软件包安装的。 二进制文件似乎没有正确设置我的Python路径,因此我添加'/usr/local/lib/python2.6/site-packages'了.bash_profile >>> pprint.pprint(sys.path) ['', '/Users/Bryan/work/django-trunk', '/usr/local/lib/python2.6/site-packages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages'] 显然,这不是所有必需的路径,因为我无法运行iPython。 $ ipython Traceback (most recent call last): File "/usr/local/bin/ipython", line 5, in <module> from pkg_resources import load_entry_point ImportError: No module named `pkg_resources` 我已经完成了Google搜索,但无法真正确定如何安装pkg_resources或确保它在路上。 我需要怎么做才能解决此问题?
82 python  ipython 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.