嗨,我通常使用conda来管理我的环境,但是现在我在一个项目中需要比笔记本电脑更大的功率。因此,我尝试使用大学的工作站,该工作站具有新的Intel Xeon。但是我没有管理员权限,并且工作站也没有conda,因此我不得不使用virtualenv和pip3。
如何requirements.txt从conda 生成可与pip3and 一起使用的from venv?
conda list -e > requirements.txt
Run Code Online (Sandbox Code Playgroud)
不会生成兼容文件:
= is not a valid operator. Did you mean == ?
Run Code Online (Sandbox Code Playgroud)
该conda输出是:
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
certifi=2016.2.28=py36_0
cycler=0.10.0=py36_0
freetype=2.5.5=2
icu=54.1=0
libpng=1.6.30=1
matplotlib=2.0.2=np113py36_0
mkl=2017.0.3=0
numpy=1.13.1=py36_0
openssl=1.0.2l=0
pip=9.0.1=py36_1
pyparsing=2.2.0=py36_0
pyqt=5.6.0=py36_2
python=3.6.2=0
python-dateutil=2.6.1=py36_0
pytz=2017.2=py36_0
qt=5.6.2=2
readline=6.2=2
scikit-learn=0.19.0=np113py36_0
scipy=0.19.1=np113py36_0
setuptools=36.4.0=py36_1
sip=4.18=py36_0
six=1.10.0=py36_0
sqlite=3.13.0=0
tk=8.5.18=0
wheel=0.29.0=py36_0
xz=5.2.3=0 …Run Code Online (Sandbox Code Playgroud) 我试图理解一段相对简单的代码,但我不太能理解发生了什么(我是来自 Python/Matlab 背景的 Julia 新手)。
function myfunc(number::Integer)
double() = 2*number
square() = number^2
return _ -> (number, double, square)
end
Run Code Online (Sandbox Code Playgroud)
我知道myfunc正在返回一个不关心传递给它的值的匿名函数。所以这些案例对我来说很有意义:
julia> n4 = myfunc(4)
#9 (generic function with 1 method)
julia> n4(50)
(4, var"#double#10"{Int64}(4), var"#square#11"{Int64}(4))
Run Code Online (Sandbox Code Playgroud)
第一行n4引用匿名函数本身,而在第二行中,匿名函数使用参数调用50并执行它应该做的事情:丢弃 50 并返回包含定义它的数据的元组。
我不明白的是我如何能够做到:
julia> n4.square
(::var"#square#11"{Int64}) (generic function with 1 method)
julia> n4.square()
16
Run Code Online (Sandbox Code Playgroud)
这事实上n4是指一个匿名函数子对象n4.number,n4.double,n4.square是一个让我吃惊。n4表现得如何,好像它是一个结构?做n4(*)[2]()返回 8 作为答案是有道理的,但是当fieldnames(n4)失败时,幕后会发生一些我不明白的 …
考虑这个ADT:
data Property f a = Property String (f a) | Zilch
deriving Show
Run Code Online (Sandbox Code Playgroud)
这是什么f?它是一个功能a吗?它是'类型函数'吗?教练说Haskell有一个图灵完整类型的语言......所以在这种情况下,类型也可以具有函数我假设?
*Main> var = Property "Colors" [1,2,3,4]
*Main> :t var
var :: Num a => Property [] a
Run Code Online (Sandbox Code Playgroud)
怎么f样[]在这里?既然[]是空列表的构造函数,那么它f总是将成为a以下示例中类型的最外面的空构造函数?
*Main> var = Property "Colors" [(1,"Red"),(2,"Blue")]
*Main> :t var
var :: Num t => Property [] (t, [Char])
*Main> var = Property "Colors" (1,"Red")
*Main> :t var
var :: Num t => Property …Run Code Online (Sandbox Code Playgroud) 这是一个与这个广受欢迎的问题有关的问题。在该问题中,我看到了有关如何在散点图等不同坐标上绘制图像(或不同图像)的答案。
使用TextArea我可以将小字符串而不是图像放在不同的坐标处。
如果我想放置由matplotlib本身生成的绘图/图像的迷你版,该怎么办?假设我要使用散点图中的图像作为image.jpg结果,而不是使用I。plt.stem(arr)
我怎样才能做到这一点?微型版本的输出plt.plot(x, y)怎么样?
我试图将链接问题中给出的功能修改为:
def stem_scatter(x, y, arr, ax=None):
from matplotlib.offsetbox import AnnotationBbox, DrawingArea
if ax is None:
ax = plt.gca()
im = DrawingArea(0.1, 0.1)
im.add_artist(plt.stem(arr))
x, y = np.atleast_1d(x, y)
artists = []
for x0, y0 in zip(x, y):
ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
artists.append(ax.add_artist(ab))
ax.update_datalim(np.column_stack([x, y]))
ax.autoscale()
return artists
Run Code Online (Sandbox Code Playgroud)
但这给出了一个错误:
AttributeError: 'StemContainer' object has no attribute 'is_transform_set'
编辑:从链接的问题:
"…. but the second has a large …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Python 中学习 Julia,我在exercism.io上发现了一段有趣的代码。用户做了一个优雅的技巧来创建包含函数的元组,因为它们是 Julia 中的一流对象。建立在我想尝试一些东西的基础上。
假设我有一个列表:
my_list = zip(0:3, ["wink", "double blink", "close your eyes", "jump"]) |> collect
Run Code Online (Sandbox Code Playgroud)
我想创建一个由 2 元素元组组成的列表,其中第二个元素是一个函数:
codes = [(i, x -> push!(x,j)) for (i,j) in my_list]
append!(codes, (4, reverse!))
Run Code Online (Sandbox Code Playgroud)
代码无法运行。检查 REPL 中的签名我意识到上面的第一行生成了一个带有签名的列表:4-element Array{Tuple{Int64,var"#68#70"{String}},1}:
而如果我像链接代码那样手动执行该过程:
codes =
[ (0, i -> push!(i, "wink"))
, (1, i -> push!(i, "double blink"))
, (2, i -> push!(i, "close your eyes"))
, (3, i -> push!(i, "jump"))
, (4, reverse!)]
Run Code Online (Sandbox Code Playgroud)
我得到正确的类型:5-element Array{Tuple{Int64,Function},1} …
有谁知道如何增加 MATLAB Control System Toolbox 生成的奈奎斯特图中箭头的大小(同时保持线宽和图中的其他所有内容相同)?
shelve只读模式坏了吗?文档说该flag参数的工作原理如中所述,dbm.open所以我认为如果我以读取模式打开,我不应该能够更改搁置对象。
这里的页面似乎还建议修改以只读方式打开的搁置对象应该引发异常。但我仍然可以执行以下操作:
\n\nPython 3.7.2 (default, Dec 29 2018, 06:19:36) \n[GCC 7.3.0] :: Anaconda, Inc. on linux\nType "help", "copyright", "credits" or "license" for more information.\n>>> import shelve\n>>> with shelve.open(\'testdata\') as shelf:\n... shelf[\'two\'] = 2222\n... shelf[\'one\'] = 1111\n... \nRun Code Online (Sandbox Code Playgroud)\n\n接下来我将用 和 打开它flag=\'r\',只是writeback=False为了确定一下。但我可以修改对象。
>>> with shelve.open(\'testdata\', flag=\'r\', writeback=False) as shelf:\n... for k, v in shelf.items():\n... print(\'Key: \', k, \' Value: \', v)\n... shelf[\'two\'] = 1111\n... shelf[\'one\'] = 2222\n... \nKey: …Run Code Online (Sandbox Code Playgroud) 我有一个涉及图形的可视化问题。我有N节点,属于某些M网络。节点可以具有网络间边缘(在同一网络内)和网络内边缘(从一个网络中的节点到另一个网络的边缘)。
当我可视化图中的图形时,networkx我正在寻找一种将网络放置/聚在一起的方法,以便可以轻松识别出内部/内部网络连接。因此,理想情况下,所有蓝色节点都应作为网络群集在一起(没有特定顺序)。橙色或绿色也是如此。
顺便说一句,我没有试图找到集线器/集群,而是知道哪些节点在哪个网络中,我只是想找到一种方法来可视化它的整洁度。有一些简单的方法可以做到这一点吗?诸如高级弹簧布局之类的东西,无论边缘权重/弹簧力如何,我都可以指定一些节点应同时出现?
import string, random
import networkx as nx
import matplotlib.pyplot as plt
from scipy.sparse import random as sparse_random
# Random string generator
def rand_string(size=6, chars=string.ascii_uppercase):
return ''.join(random.choice(chars) for _ in range(size))
# Set up a nodes and networks randomly
nodes = [rand_string() for _ in range(30)]
networks = [rand_string() for _ in range(5)]
networks_list = networks*6
random.shuffle(networks_list)
# Define what nodes belong to what network and what their color …Run Code Online (Sandbox Code Playgroud) 该__invert__方法的目的是什么?我在探索 Python 内部结构时遇到了:
>>> dir(__builtins__.int)
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是:
__builtins__.int().__invert__()
Run Code Online (Sandbox Code Playgroud)
这似乎打破了所有数学规则,因为 …
如果我完全遗漏了一些明显的东西,或者如果我没有足够努力地研究文档,我深表歉意,但在 30 分钟左右后,我找到了一个解决方法(没有理解我遇到的错误)并且......因此这里的问题。假设我有一堂课:
class RGB(object):
def __init__(self, r, g, b):
super(RGB, self).__init__()
self.red = r
self.blue = b
self.green = g
Run Code Online (Sandbox Code Playgroud)
我定义了一个实例列表,RGB如下所示:
from random import random
rr, gg, bb = [[random() for _ in range(20)] for _ in range(3)]
list_of_rgbs = [RGB(*item) for item in zip(rr, gg, bb)]
Run Code Online (Sandbox Code Playgroud)
为什么我不能通过执行以下操作来提取值列表red:
from functools import partial
*reds, = map(partial(getattr, name="red"), list_of_rgbs)
Run Code Online (Sandbox Code Playgroud)
或者
*reds, = map(partial(getattr, "red"), list_of_rgbs)
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过说让它做我想做的事情,reds = [x.red for x in list_of_rbgs]但是如果要提取的属性列表来自其他地方,例如:,那就很困难了attribs_to_get = ['red', …
python-3.x ×4
python ×3
julia ×2
conda ×1
functools ×1
haskell ×1
matlab ×1
matplotlib ×1
networkx ×1
pip ×1
python-3.7 ×1
shelve ×1
types ×1