我想在绘图的两边用matplotlib画一个带有轴的图,类似于这个图(颜色与这个问题无关):

我怎么能这样做matplotlib?
注意:与示例图中显示的相反,我希望两个轴完全相同,并且只想显示一个图.添加两个轴只是为了更容易读取图形.
我正在尝试获取已经分箱数据的直方图.我一直在尝试使用bar()它,但我似乎无法弄清楚如何使它成为像这样的阶梯式直方图,而不是填充的直方图.

给出最小的C++ 11 STL示例:
set<int> S = {1,2,3,4};
for(auto &x: S) {
cout << x;
cout << ",";
}
Run Code Online (Sandbox Code Playgroud)
有没有办法x在结束前检查是否正确?此示例中的目标是输出1,2,3,4而不是最后的最后一个逗号.目前我使用带有两个迭代器的标准for循环,
set<int>::const_iterator itr;
set<int>::const_iterator penultimate_end_itr = --S.end();
for(itr=S.begin(); itr!=penultimate_end_itr;++itr)
cout << (*itr) << ',';
cout << (*penultimate_end_itr);
Run Code Online (Sandbox Code Playgroud)
哪个有效,但非常麻烦.有没有办法在基于范围的for循环中进行检查?
编辑:问题的关键是不打印逗号分隔列表.我想知道基于范围的for循环是否具有列表中倒数第二个元素的任何知识(即它是在结束之前的一个).提出了最小的例子,所以我们都有一个共同的代码块来讨论.
我有两个矩阵Tri,并V为我要绘制多边形面(NX3)和顶点(MX3).有没有matplotlib(或任何替代)的方式来做到这一点?类似于Matlab命令的东西
patch('faces',Tri,'vertices',V,'facecolor',
'flat','edgecolor','none','facealpha',1)
Run Code Online (Sandbox Code Playgroud) 我正在试图弄清楚如何访问LinkedIn上的任何公司资料.例如,LinkedIn本身的REST端点API是:
https://api.linkedin.com/v1/companies/1337?format=json
Run Code Online (Sandbox Code Playgroud)
样本响应:
{
"id": 1337,
"name": "LinkedIn"
}
Run Code Online (Sandbox Code Playgroud)
但是,在rw_company_admin启用OAuth2进行身份验证后,我的应用会返回:
{
"errorCode": 0,
"message": "Member 206xxxxxx does not have permission to get company 1337",
"requestId": "G6LNMCEZO8",
"status": 403,
"timestamp": 1432358171348
}
Run Code Online (Sandbox Code Playgroud)
这一直持续到最近.
该文档确实注意到 "为了执行下面的任何公司页面管理API调用,提出请求的经过身份验证的LinkedIn用户必须是目标公司的管理员." 令人困惑的是,它还说 "以下终端是唯一可以继续使用的终端......公司API - /v1/companies/{id}".
但是,我的目标不是管理公司作为管理员,而是向用户显示公司的简要输出.我怎样才能获得公司信息?
我想在Keras中获得预先训练的VGG16模型,删除其输出层,然后放置一个新的输出层,其中包含适合我的问题的类数,然后将其放在新数据上.出于这个原因,我试图在这里使用这个模型:https://keras.io/applications/#vgg16,但由于它不是Sequential,我不能只是model.pop().从图层弹出并添加它也不起作用,因为在预测中它仍然期望旧的形状.我该怎么办?有没有办法将这种类型的模型转换为Sequential?
我目前正在使用这个代码,我从github 上的一个讨论得到这里是注意机制的代码:
_input = Input(shape=[max_length], dtype='int32')
# get the embedding layer
embedded = Embedding(
input_dim=vocab_size,
output_dim=embedding_size,
input_length=max_length,
trainable=False,
mask_zero=False
)(_input)
activations = LSTM(units, return_sequences=True)(embedded)
# compute importance for each step
attention = Dense(1, activation='tanh')(activations)
attention = Flatten()(attention)
attention = Activation('softmax')(attention)
attention = RepeatVector(units)(attention)
attention = Permute([2, 1])(attention)
sent_representation = merge([activations, attention], mode='mul')
sent_representation = Lambda(lambda xin: K.sum(xin, axis=-2), output_shape=(units,))(sent_representation)
probabilities = Dense(3, activation='softmax')(sent_representation)
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?我有点期待时间分布层的存在,因为注意机制分布在RNN的每个时间步骤中.我需要有人确认这个实现(代码)是一个正确的注意机制实现.谢谢.
我在使用Find()方法的行中得到以下异常(缺少主键)
"表没有主键."
我已经重新检查了数据库,并且所有主键列都已正确设置.
我的代码:
DataTable dt = p.GetAllPhotos(int.Parse(Id));
DataTable temp = new DataTable();
temp = dt.Clone();
temp = (DataTable)(Session["currentImage"]);
DataTable dtvalid = new DataTable();
dtvalid = dt.Clone();
DataRow[] drr = new DataRow[1];
drr[0] = dt.Rows.Find((int.Parse(temp.Rows[0]["photoId"].ToString()))+1);
foreach (DataRow dr in drr)
{
dtvalid.ImportRow(dr);
}
dtvalid.AcceptChanges();'
Run Code Online (Sandbox Code Playgroud) 使用python的multiprocessing模块,以下设计的示例以最小的内存要求运行:
import multiprocessing
# completely_unrelated_array = range(2**25)
def foo(x):
for x in xrange(2**28):pass
print x**2
P = multiprocessing.Pool()
for x in range(8):
multiprocessing.Process(target=foo, args=(x,)).start()
Run Code Online (Sandbox Code Playgroud)
取消注释的创建,completely_unrelated_array你会发现每个衍生的进程分配内存为completely_unrelated_array!这是一个更大的项目的最小例子,我无法弄清楚如何解决方法; 多处理似乎可以复制全局的所有内容.我并不需要共享内存对象,我只需要传递x和处理它没有整个程序的内存开销.
侧面观察:有趣的是print id(completely_unrelated_array)内部foo给出相同的值,暗示某些可能不是副本......
通过Keras神经网络运行一组标记的向量.
查看Keras数据集示例mnist:
keras.datasets import mnist
(x_tr, y_tr), (x_te, y_te) = mnist.load_data()
print x_tr.shape
Run Code Online (Sandbox Code Playgroud)
它似乎是一个三维numpy数组:
(60000, 28, 28)
Run Code Online (Sandbox Code Playgroud)
构建标记的向量:
X_train = numpy.array([[1] * 128] * (10 ** 4) + [[0] * 128] * (10 ** 4))
X_test = numpy.array([[1] * 128] * (10 ** 2) + [[0] * 128] * (10 ** 2))
Y_train = numpy.array([True] * (10 ** 4) + [False] * (10 ** 4))
Y_test = numpy.array([True] * (10 ** 2) + …Run Code Online (Sandbox Code Playgroud)