什么是确定python中条形图的偏斜/峰度的有效方法?考虑到条形图没有分箱(与直方图不同),这个问题没有多大意义,但我想要做的是确定图形高度与距离的对称性(而不是频率与分档).换句话说,给定沿距离(x)测量的高度(y)值,即
y = [6.18, 10.23, 33.15, 55.25, 84.19, 91.09, 106.6, 105.63, 114.26, 134.24, 137.44, 144.61, 143.14, 150.73, 156.44, 155.71, 145.88, 120.77, 99.81, 85.81, 55.81, 49.81, 37.81, 25.81, 5.81]
x = [0.03, 0.08, 0.14, 0.2, 0.25, 0.31, 0.36, 0.42, 0.48, 0.53, 0.59, 0.64, 0.7, 0.76, 0.81, 0.87, 0.92, 0.98, 1.04, 1.09, 1.15, 1.2, 1.26, 1.32, 1.37]
Run Code Online (Sandbox Code Playgroud)
在距离(x)上测量的高度(y)分布(偏度)和峰值(峰度)的对称性是多少?偏度/峰度是否适合用于确定实际值的正态分布?或者scipy/numpy是否为这种类型的测量提供类似的东西?
我可以通过以下方式实现沿距离(x)分箱的高度(y)频率值的偏斜/峰度估计
freq=list(chain(*[[x_v]*int(round(y_v)) for x_v,y_v in zip(x,y)]))
x.extend([x[-1:][0]+x[0]]) #add one extra bin edge
hist(freq,bins=x)
ylabel("Height Frequency")
xlabel("Distance(km) Bins")
print "Skewness,","Kurtosis:",stats.describe(freq)[4:]
Skewness, Kurtosis: (-0.019354300509997705, -0.7447085398785758)
Run Code Online (Sandbox Code Playgroud)
在这种情况下,高度分布在中点距离附近是对称的(偏斜0.02)并且以扁平(-0.74峰度,即宽)分布为特征. …
我想升级matplotlib在Ubuntu 12.04.当我运行命令时:
sudo pip install --upgrade matplotlib
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Downloading/unpacking matplotlib
Running setup.py egg_info for package matplotlib
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24dev-r0 (/usr/lib/python2.7/dist-packages))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please …Run Code Online (Sandbox Code Playgroud) 我正在读取文件并使用以下行导入其中的数据:
# Read data from file.
data = np.loadtxt(join(mypath, 'file.data'), unpack=True)
Run Code Online (Sandbox Code Playgroud)
知道变量的地方mypath.问题是文件file.data会随着时间而变化,假设名称如下:
file_3453453.data
file_12324.data
file_987667.data
...
Run Code Online (Sandbox Code Playgroud)
因此,我需要一种方法来告诉代码在该路径中打开具有类似名称的文件file*.data,假设路径中始终只有该名称的一个文件.有没有办法做到这一点python?
我有一系列行存储在列表中,如下所示:
line_list = [line_1, line_2, line_3, ..., line_M]
Run Code Online (Sandbox Code Playgroud)
其中每个line_i是由两个子子列表组成的子列表,一个用于x坐标,另一个用于y坐标:
line_i = [[x_1i, x2_i, .., x_Ni], [y_1i, y_2i, .., y_Ni]]
Run Code Online (Sandbox Code Playgroud)
我也有一个line_list与花车相同长度的列表,:
floats_list = [0.23, 4.5, 1.6, ..., float_M]
Run Code Online (Sandbox Code Playgroud)
我想绘制每一行,给它一个颜色图中的颜色,并与floats_list列表中索引的位置相关.因此line_j它的颜色将由数字决定floats_list[j].我还需要在侧面显示一个颜色条
代码会喜欢这样的东西,除了它应该工作:)
import matplotlib.pyplot as plt
line1 = [[0.5,3.6,4.5],[1.2,2.0,3.6]]
line2 = [[1.5,0.4,3.1,4.9],[5.1,0.2,7.4,0.3]]
line3 = [[1.5,3.6],[8.4,2.3]]
line_list = [line1,line2,line3]
floats_list = [1.2,0.3,5.6]
# Define colormap.
cm = plt.cm.get_cmap('RdYlBu')
# plot all lines.
for j,lin in enumerate(line_list):
plt.plot(lin[0], lin[1], c=floats_list[j])
# Show colorbar.
plt.colorbar()
plt.show()
Run Code Online (Sandbox Code Playgroud) 我有三个由相同数量的元素组成的列表:
a = [0.3, 1.5, 0.2, 2.6]
b = [1, 2, 3, 4]
c = [0.01, 0.02, 0.03, 0.04]
Run Code Online (Sandbox Code Playgroud)
我需要根据列表中的递减值同时对这三个列表进行排序a.这意味着我必须按照排序,a但a也需要进行排序.输出应如下所示:
a_s = [2.6, 1.5, 0.3, 0.2]
b_s = [4, 2, 1, 3]
c_s = [0.04, 0.02, 0.01, 0.03]
Run Code Online (Sandbox Code Playgroud)
这样,a_s现在简单地使用,同时降低值进行排序b_s,并c_s根据此排序改变了项目的位置.
在对git我已经跟踪的文件进行更改后,通常会执行以下操作:
git commit -a -m "a message describing what you did"
Run Code Online (Sandbox Code Playgroud)
其次是
git push origin master
Run Code Online (Sandbox Code Playgroud)
提交然后将所有更改推送到我的Github帐户.但是,第一个命令不适用于添加或删除的提交文件.要做到这一点,我将首先输入:
git add -A
Run Code Online (Sandbox Code Playgroud)
如下所述:如何提交和推送所有更改,包括删除?.
在另一个问题中,Git使用单个命令提交所有文件,接受的答案表明应用完整提交的唯一方法(即:包括添加或删除的文件,不仅仅是编辑过)然后推送是通过将它们与&&命令结合起来,如此:
git add -A && git commit
Run Code Online (Sandbox Code Playgroud)
在我的情况下看起来像:
git add -A && git commit -a -m "a message describing what you did" && git push origin master
Run Code Online (Sandbox Code Playgroud)
现在问题是:这个大命令是否正确?有没有办法创建一个新git命令来同时应用这三个命令?此外:推荐或劝阻这些命令的合并?如果是,请说明原因.
我立刻后悔这个决定:编辑上次推送提交的消息.
我需要计算两个函数重叠的区域.我在这个特定的简化示例中使用了正态分布,但我需要一个更通用的过程来适应其他函数.
请参阅下面的图片,了解我的意思,红色区域是我所追求的:

这是我到目前为止的MWE:
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
# Generate random data uniformly distributed.
a = np.random.normal(1., 0.1, 1000)
b = np.random.normal(1., 0.1, 1000)
# Obtain KDE estimates foe each set of data.
xmin, xmax = -1., 2.
x_pts = np.mgrid[xmin:xmax:1000j]
# Kernels.
ker_a = stats.gaussian_kde(a)
ker_b = stats.gaussian_kde(b)
# KDEs for plotting.
kde_a = np.reshape(ker_a(x_pts).T, x_pts.shape)
kde_b = np.reshape(ker_b(x_pts).T, x_pts.shape)
# Random sample from a KDE distribution.
sample = ker_a.resample(size=1000)
# Compute …Run Code Online (Sandbox Code Playgroud) 我在文件夹中有许多文件,其名称遵循约定:
0.1.txt, 0.15.txt, 0.2.txt, 0.25.txt, 0.3.txt, ...
Run Code Online (Sandbox Code Playgroud)
我需要逐个阅读它们并操纵它们内部的数据.目前我用命令打开每个文件:
import os
# This is the path where all the files are stored.
folder path = '/home/user/some_folder/'
# Open one of the files,
for data_file in os.listdir(folder_path):
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,它没有按特定的顺序读取文件(不确定它是如何选择它们)而我需要从具有最小数字作为文件名的那个开始读取它们,然后是具有直接较大数字的那个,依此类推直到最后一个.
我正在尝试为x,y点列表生成密度图,每个点都与给定的密度值相关联.看到这张图片,看看我在追求什么.
我尝试在这个答案中应用Joe Kington编写的代码,但它返回错误.numpy.linalg.linalg.LinAlgError: singular matrix
这是MWE我的代码(Joe的代码基本相同,只更改了数据数组):
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
x = np.array([0.005, 0.018, 0.008, 0.015, 0.016, 0.0135, 0.0155, 0.0155, 0.0105, 0.005, 0.0125, 0.0185, 0.0095, 0.003, 0.019, 0.0175, 0.0165, 0.011, 0.007, 0.0195, 0.017, 0.011, 0.0125, 0.0165, 0.0045, 0.0145, 0.02, 0.0185, 0.001, 0.015, 0.0105, 0.016, 0.0185, 0.0035, 0.0025, 0.0015, 0.0055, 0.0185, 0.005, 0.0135, 0.0175, 0.0095, 0.0095, 0.0115, 0.0025, 0.0105, 0.0015, 0.0045, 0.011, 0.009, 0.0045, …Run Code Online (Sandbox Code Playgroud) 我对numpy.genfromtxt包有一个奇怪的问题。我用它来读取包含多个列的数据文件(可在此处unpack找到),但即使设置为,这些列也不会被解压缩True。
这是一个MWE:
import numpy as np
f_data = np.genfromtxt('file.dat', dtype=None, unpack=True)
print f_data[3]
(237, 304.172, 2017.48, 15.982, 0.005, 0.889, 0.006, -2.567, 0.004, 1.205, 0.006)
Run Code Online (Sandbox Code Playgroud)
(我使用dtype=None是因为文件中可能有分散的字符串)
正如您所看到的,它返回一行而不是未打包的列。
如果我使用np.loadtxt它,它会按预期工作:
f_data = np.loadtxt('file.dat', unpack=True)
print f_data[3]
[ 16.335 16.311 15.674 15.982 16.439 15.903 15.313 18.35 15.643 14.081 16.578 11.477]
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
python ×9
numpy ×4
file-io ×2
matplotlib ×2
scipy ×2
arrays ×1
canopy ×1
density-plot ×1
enthought ×1
git ×1
github ×1
montecarlo ×1
naming ×1
sorting ×1
upgrade ×1