在Windows PowerShell上重定向标准输入/输出所需的语法是什么?
在Unix上,我们使用:
$./program <input.txt >output.txt
Run Code Online (Sandbox Code Playgroud)
如何在PowerShell中执行相同的任务?
我想在地图上绘制一个图形,其中节点将由坐标(纬度,长度)定义并且具有一些值相关联.
我已经能够将点绘制为底图上的散点图,但似乎无法找到如何在地图上绘制图形.
谢谢.
编辑:我添加了关于如何在底图上绘制点的代码.它的大部分是改编自代码在这个文章.
from mpl_toolkits.basemap import Basemap
from shapely.geometry import Point, MultiPoint
import pandas as pd
import matplotlib.pyplot as plt
m = Basemap(
projection='merc',
ellps = 'WGS84',
llcrnrlon=-130,
llcrnrlat=25,
urcrnrlon=-60,
urcrnrlat=50,
lat_ts=0,
resolution='i',
suppress_ticks=True)
# Create Point objects in map coordinates from dataframe lon
# and lat values
# I have a dataframe of coordinates
map_points = pd.Series(
[Point(m(mapped_x, mapped_y))
for mapped_x, mapped_y in zip(df['lon'],
df['lat'])])
amre_points = MultiPoint(list(map_points.values))
plt.clf()
fig = plt.figure()
ax = fig.add_subplot(111, …Run Code Online (Sandbox Code Playgroud) 我一直在将用于isomap算法的代码从MATLAB移植到Python.我试图使用间谍功能可视化稀疏模式.
MATLAB命令:
spy(sparse(A));
drawnow;
Run Code Online (Sandbox Code Playgroud)
Python命令:
matplotlib.pyplot.spy(scipy.sparse.csr_matrix(A))
plt.show()
Run Code Online (Sandbox Code Playgroud)
我无法使用上面的命令在Python中重现MATLAB结果.使用仅具有非稀疏格式的A的命令可以得到与MATLAB非常相似的结果.但这需要很长时间(A为2000×2000).对于scipy,MATLAB等效的稀疏函数是什么?
我有一个情节,我通过scikit-learn中的KMeans算法生成.簇对应于不同的颜色.这是情节,

我需要一个这个图的图例,它对应于图中的簇编号.理想情况下,图例应显示群集的颜色,标签应为群集编号.谢谢.
编辑:我认为我应该放一些代码,因为人们正在贬低这个
from sklearn.cluster import KMeans
km = KMeans(n_clusters=20, init='random')
km.fit(df) #df is the dataframe which contains points as coordinates
labels = km.labels_
plt.clf()
fig = plt.figure()
ax = fig.add_subplot(111, axisbg='w', frame_on=True)
fig.set_size_inches(18.5, 10.5)
# Plot the clusters on the map
# m is a basemap object
m.scatter(
[geom.x for geom in map_points],
[geom.y for geom in map_points],
20, marker='o', lw=.25,
c = labels.astype(float),
alpha =0.9, antialiased=True,
zorder=3)
m.fillcontinents(color='#555555')
plt.show()
Run Code Online (Sandbox Code Playgroud) 为什么我不能实例化一个抽象类,而是创建一个抽象类的数组?
public abstract class Game{
...
}
Game games = new Game(); //Error
Game[] gamesArray = new Game[10]; //No Error
Run Code Online (Sandbox Code Playgroud) 我想知道KMeans在进行群集之前是否会自动规范化功能.似乎没有提供输入来请求规范化的选项.
我有一个使用unittest测试模块的脚本.当我使用python控制台运行脚本时,我得到输出:
test_equal (__main__.TestOutcome) ... ok
test_win_amount (__main__.TestOutcome) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
Run Code Online (Sandbox Code Playgroud)
但是,在使用IPython控制台运行相同的脚本时,我没有得到任何输出.
我使用以下命令来运行我的脚本,
suite = unittest.TestLoader().loadTestsFromTestCase(TestOutcome)
unittest.TextTestRunner(verbosity=2).run(suite)
Run Code Online (Sandbox Code Playgroud)
任何想法,如果这可能是由于IPython设置?
我有一组数据点,如图所示。

我需要将曲线拟合到这些点,以使曲线单调递减。曲线没有指定的功能形式。我第一次尝试曲线拟合,总的来说,我想知道如何继续进行某些功能的选择,拟合和比较拟合以选择最佳功能。
我认为对于单调递减的曲线,约束条件是一阶导数为负。我正在查看scipy.curve_fit和scipy.interpolate.UnivariateSpline函数,但是它们似乎没有约束拟合的选项。在这种情况下使用的最佳功能是什么?谢谢。
我想在networkx图中获取边缘的颜色条.这是一段代码片段
import networkx as nx
import matplotlib.colors as colors
import matplotlib.cm as cmx
n = 12 # Number of clusters
w = 21 # Number of weeks
m = Basemap(
projection='merc',
ellps = 'WGS84',
llcrnrlon=-98.5,
llcrnrlat=25,
urcrnrlon=-60,
urcrnrlat=50,
lat_ts=0,
resolution='i',
suppress_ticks=True)
mx, my = m(list(ccentroids['lon']), list(ccentroids['lat']))
# The NetworkX part
# put map projection coordinates in pos dictionary
G = nx.DiGraph()
G.add_nodes_from(range(n))
for i in range(n):
for j in range(n):
if P_opt[i,j] > 0.5 and i != j:
G.add_edge(i,j, weight …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 GridsearchCV 在 sklearn 中调整 GB 分类器。这是代码:
from sklearn.grid_search import GridSearchCV
from sklearn.ensemble import GradientBoostingClassifier
param_grid = {'learning_rate': [0.1, 0.01, 0.001],
'max_depth': [4, 6],
'min_samples_leaf': [9, 17],
'max_features': [0.3, 0.1]}
est = GradientBoostingClassifier(n_estimators=3000)
# this may take some minutes
gs_cv = GridSearchCV(est, param_grid, scoring='f1', n_jobs=-1, verbose=1, pre_dispatch=5).fit(X.values, y)
# best hyperparameter setting
print 'Best hyperparameters: %r' % gs_cv.best_params_
Run Code Online (Sandbox Code Playgroud)
数据集 X 是 100 万行 * 245 个特征。我在一台接近 32 个内核的机器上运行。当我运行上面的代码时出现以下错误,
error Traceback (most recent call last)
<ipython-input-22-cb545fec9989> in <module>()
9 est = …Run Code Online (Sandbox Code Playgroud) python ×7
networkx ×2
scikit-learn ×2
scipy ×2
arrays ×1
grid-search ×1
ipython ×1
java ×1
legend ×1
matlab ×1
matplotlib ×1
numpy ×1
plot ×1
powershell ×1
stdin ×1