我从我当前环境缺少的包的 yml 文件中获取了这些。我如何在我当前的环境中安装这些?
channels:
- defaults
dependencies:
- appdirs=1.4.3=py36h28b3542_0
- asn1crypto=0.24.0=py36_0
- attrs=18.2.0=py36h28b3542_0
- blas=1.0=mkl
- cffi=1.11.5=py36h6174b99_1
- constantly=15.1.0=py36h28b3542_0
- cryptography=2.3.1=py36hdbc3d79_0
- freetype=2.9.1=hb4e5f40_0
- html5lib=1.0.1=py36_0
- idna=2.7=py36_0
- incremental=17.5.0=py36_0
- intel-openmp=2019.0=118
- libgfortran=3.0.1=h93005f0_2
- libxml2=2.9.4=0
- libxslt=1.1.29=hc208041_6
- lxml=4.1.1=py36h6c891f4_0
- mkl=2019.0=118
- mkl_fft=1.0.6=py36hb8a8100_0
- mkl_random=1.0.1=py36h5d10147_1
- numpy=1.15.3=py36h6a91979_0
- numpy-base=1.15.3=py36h8a80b8c_0
- pyasn1=0.4.4=py36h28b3542_0
- pyasn1-modules=0.2.2=py36_0
- pycparser=2.19=py36_0
- pyopenssl=18.0.0=py36_0
- service_identity=17.0.0=py36h28b3542_0
- twisted=17.5.0=py36_0
- zope=1.0=py36_1
- zope.interface=4.5.0=py36h1de35cc_0
- pip:
- absl-py==0.2.2
- ete3==3.1.1
- grpcio==1.12.1
Run Code Online (Sandbox Code Playgroud) 如果您使用python写入文件,是否有任何方法可以使文本的某些部分变为粗体,斜体或下划线?
我试过了:
test = '/location/tester.rtf'
out_file = open(test,'w')
out_file.write('is this {\bold}?')
out_file.close() #thanks to the comment below
Run Code Online (Sandbox Code Playgroud)
是否可以通过python编写格式化的文本,如粗体,斜体或带下划线的文本?我觉得.rtf是最基本的格式化文本,但如果我错了,请纠正我
我处理大量dtype="str"数据.我一直在尝试构建一个简单的图形,如https://www.tensorflow.org/versions/master/api_docs/python/train.html#SummaryWriter.
对于一个简单的操作,我想使用placeholderas(如何为占位符提供?)将字符串连接在一起?
有谁知道如何将字符串张量合并在一起?
import tensorflow as tf
sess = tf.InteractiveSession()
with tf.name_scope("StringSequence") as scope:
left = tf.constant("aaa",name="LEFT")
middle = tf.placeholder(dtype=tf.string, name="MIDDLE")
right = tf.constant("ccc",name="RIGHT")
complete = tf.add_n([left,middle,right],name="COMPLETE") #fails here
sess.run(complete,feed_dict={middle:"BBB"})
#writer = tf.train.SummaryWriter("/users/mu/test_out/", sess.graph_def)
Run Code Online (Sandbox Code Playgroud) 我正在试图弄清楚如何将轴附加到我的极地投影上.新添加的轴应该像环一样环绕原始极轴.
为此,我尝试使用matplotlib投影上append_axes创建的分隔符.make_axes_locatablepolarax
但是,"外部"或任何类似极性投影的append_axes参数都没有选择.我没有围绕轴的环,而是在原始轴下方获得一个新轴(见图).
有没有可以在现有极轴周围创建环形轴的替代方案?
注意,我不想将它们添加到同一个轴上,因为比例可能不同.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
plt.style.use("seaborn-white")
def synthesize(polar=False):
fig = plt.figure()
ax = fig.add_subplot(111, polar=polar)
t = np.linspace(0,2*np.pi)
r_sin = np.sin(t)
r_cos = np.cos(t)
for r in [r_sin, r_cos]:
ax.scatter(t, r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
ax.scatter(t, -r, c=r, s=t*100, edgecolor="white", cmap=plt.cm.magma_r)
ax.set_title("polar={}".format(polar),fontsize=15)
ax.set_xticklabels([])
return fig, ax, t
# Rectilinear
fig, ax, t = synthesize(polar=False)
# Here are the plot dimensions in …Run Code Online (Sandbox Code Playgroud) 我知道有一些包可以为我做双标图,但我想了解这些加载是如何绘制的,因为到目前为止它看起来像巫术。
我的理解如下:
我正在将我的结果与 PCA 包 ( https://github.com/erdogant/pca ) 进行比较,因为我比我的直觉更相信这些结果。我试图弄清楚我的逻辑哪里有缺陷以及我的绘图做错了什么。在原始的源代码开始绘制双标图这里。
虹膜示例看起来很准确,但我的小样本珊瑚基因表达气候变化数据集看起来根本不正确。
我似乎无法弄清楚我做错了什么。任何帮助都会很棒。
import matplotlib.pyplot as plt
from matplotlib.patches import ConnectionPatch
from sklearn.decomposition import PCA
from sklearn.datasets import load_iris
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
# Test version to understand how loadings are plotted
def plot_biplot(
data:pd.DataFrame,
arrow_scale=1,
n_feat=4,
):
# Build PCA
model = PCA(n_components=min(data.shape))
projection = pd.DataFrame(model.fit_transform(data), index=data.index)
projection.columns = projection.columns.map(lambda j: "PC.{}".format(j+1))
projection = projection.iloc[:,:2] …Run Code Online (Sandbox Code Playgroud) def FileCheck(fn):
try:
fn=open("TestFile.txt","U")
except IOError:
print "Error: File does not appear to exist."
return 0
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个函数来检查文件是否存在,如果不存在,那么它应该打印错误消息并返回0.为什么不工作?
所以我有一个DataFrame,我把列标记为a - i.我想Dictionary of Dictionaries在外键为"a"列,内键为"d"列,值为"e".我知道如何通过迭代每一行来做到这一点,但我觉得有一种更有效的方法来实现这一点,DataFrame.to_dict()但我无法弄清楚如何...也许DataFrame.group_by可以帮助,但似乎用于分组列或索引ID.
如何在不迭代每一行的情况下使用pandas(或numpy)Dictionary of Dictionaries有效地创建?我已经展示了我当前方法的一个示例以及下面所需的输出.
#!/usr/bin/python
import numpy as np
import pandas as pd
tmp_array = np.array([['AAA', 86880690, 86914111, '22RV1', 2, 2, 'H', '-'], ['ABA', 86880690, 86914111, 'A549', 2, 2, 'L', '-'], ['AAC', 86880690, 86914111, 'BFTC-905', 3, 3, 'H', '-'], ['AAB', 86880690, 86914111, 'BT-20', 2, 2, 'H', '-'], ['AAA', 86880690, 86914111, 'C32', 2, 2, 'H', '-']])
DF = pd.DataFrame(tmp_array,columns=["a,b,c,d,e,g,h,i".split(",")])
#print(DF)
a b c …Run Code Online (Sandbox Code Playgroud) 我正在使用以下链接创建"Euclidean相似度矩阵"(我将其转换为DataFrame). https://stats.stackexchange.com/questions/53068/euclidean-distance-score-and-similarity http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.distance .euclidean.html
我这样做的方式是迭代方法,但是当数据集很大时需要一段时间.pandas pd.DataFrame.corr()对于皮尔森相关性来说非常快速且有用.
如何在无穷尽迭代的情况下执行欧几里得相似性度量?
我的天真代码如下:
#Euclidean Similarity
#Create DataFrame
DF_var = pd.DataFrame.from_dict({"s1":[1.2,3.4,10.2],"s2":[1.4,3.1,10.7],"s3":[2.1,3.7,11.3],"s4":[1.5,3.2,10.9]}).T
DF_var.columns = ["g1","g2","g3"]
# g1 g2 g3
# s1 1.2 3.4 10.2
# s2 1.4 3.1 10.7
# s3 2.1 3.7 11.3
# s4 1.5 3.2 10.9
#Create empty matrix to fill
M_euclid = np.zeros((DF_var.shape[1],DF_var.shape[1]))
#Iterate through DataFrame columns to measure euclidean distance
for i in range(DF_var.shape[1]):
u = DF_var[DF_var.columns[i]]
for j in range(DF_var.shape[1]):
v = DF_var[DF_var.columns[j]]
#Euclidean distance -> Euclidean similarity
M_euclid[i,j] = (1/(1+sp.spatial.distance.euclidean(u,v))) …Run Code Online (Sandbox Code Playgroud) pd.Series由于某种原因,我无法从这本字典创建一个对象.我用另一个非常相似的方式做到了.
注意:更新2018年6月 - 04年看起来有一个GitHub问题:https: //github.com/pandas-dev/pandas/issues/15457
pd.__version__
'0.23.0'
import pandas as pd
from numpy import array
import numpy as np
param_index = OrderedDict([((('criterion', 'gini'), ('max_features', 'log2'), ('min_samples_leaf', 1)), array([ 0, 40, 80, 120, 160, 200])), ((('criterion', 'gini'), ('max_features', 'log2'), ('min_samples_leaf', 2)), array([ 1, 41, 81, 121, 161, 201])), ((('criterion', 'gini'), ('max_features', 'log2'), ('min_samples_leaf', 3)), array([ 2, 42, 82, 122, 162, 202])), ((('criterion', 'gini'), ('max_features', 'log2'), ('min_samples_leaf', 5)), array([ 3, 43, 83, 123, 163, 203])), ((('criterion', 'gini'), ('max_features', 'log2'), …Run Code Online (Sandbox Code Playgroud) python ×10
pandas ×4
numpy ×3
dataframe ×2
dictionary ×2
indexing ×2
matplotlib ×2
anaconda ×1
conda ×1
except ×1
file ×1
format ×1
function ×1
fwrite ×1
installation ×1
matrix ×1
package ×1
pca ×1
plot ×1
projection ×1
row ×1
scipy ×1
series ×1
statistics ×1
string ×1
tensorflow ×1
text ×1
try-catch ×1