如何使用Scala打印列表中的第一个元素?
例如在Python中我可以写:
>>>l = [1,2,3,4]
>>>one = l[0]
>>>print one
Run Code Online (Sandbox Code Playgroud)
我怎么能在Scala上做到这一点
谢谢.
这是我的 2D numpy 数组:
returns = np.array([
[ -4.78878057e-03 9.79090927e-03 -2.06883581e-03 -1.25786164e-02]
[ 5.79128440e-03 -2.85791008e-03 1.69555388e-03 -5.63798220e-02]
[ 5.73427375e-05 2.45043133e-02 8.55025651e-03 -4.53257790e-02]
[ 6.75441635e-03 8.70168484e-03 1.07547532e-02 -1.36919315e-01]
[ 6.68332655e-03 6.76498174e-03 3.08225775e-03 0.00000000e+00]])
Run Code Online (Sandbox Code Playgroud)
当我尝试计算每列的 STD 时:
print np.std(returns, axis=1)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError: 'axis' entry is out of bounds
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
我正在尝试在我的 MEAN 堆栈应用程序上进行 facebook 授权。我正在使用passport和passport-facebook。我没有使用jadeor ejs,我想使用纯 angularjs 。当我运行应用程序并单击“登录”按钮时,出现以下错误:
XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&redirect_uri=http%\xe2\x80\xa62Flocalhost%3A3030%2Fauth%2Ffacebook%2Fcallback&client_id=.... \nNo \'Access-Control-Allow-Origin\' header is present on the requested resource. Origin \'http://localhost:3030\' is therefore not allowed access.\nRun Code Online (Sandbox Code Playgroud)\n\n我做了一些研究,发现节点cors模块可以解决这个问题,但事实并非如此。
我做错了什么以及如何解决?
\n\n这是我的routes.js 文件(服务器端):
\n\napp.get(\'/auth/facebook\', passport.authenticate(\'facebook\'));\n\napp.get(\'/auth/facebook/callback\', passport.authenticate(\'facebook\', {\n successRedirect: \'/success\',\n failureRedirect: \'/error\'\n}));\n\napp.post(\'/success\', function(req, res, next) {\n User.findById(req.session.passport.user, function(err, user) {\n if(err){ \n res.send({success:false}); \n }else{ \n res.send({success:true,user: user});\n }\n });\n});\n\napp.get(\'/logout\', function(req, res){\n req.logout();\n res.redirect(\'/\');\n res.end();\n});\n\napp.post(\'/error\', function(req, res, next) …Run Code Online (Sandbox Code Playgroud) 这里是塔林的小热图,有三个来源:

如您所见,此地图示例中没有"红色"部分.
但当我缩小时,我得到了这个:

当你缩小时我需要我的热图有橙黄绿色,而不是红色.
如何使用Heatmap和google-maps-api(可选)实现这一目标.
注意:
我做了一个缩小事件来改变半径,我认为这个事件也可以帮我解决这个问题,但我不知道我应该改变什么配置:
google.maps.event.addListener(map, 'zoom_changed', function() {
var zoomLevel = map.getZoom();
heatmap.setOptions({radius:zoomLevel*0.5});
});
Run Code Online (Sandbox Code Playgroud) 以下是在 Google Maps Api 中创建热图图层的方法:
var data = [
{location: new google.maps.LatLng(59.4072, 24.7053),weight:0.8},
{location: new google.maps.LatLng(59.4372, 24.7473),weight: 1},
{location: new google.maps.LatLng(59.4372, 24.7493),weight:0.8},
{location: new google.maps.LatLng(59.483428, 24.841709),weight: 0.6},
{location: new google.maps.LatLng(59.483256, 24.846666),weight: 0.2},
{location: new google.maps.LatLng(59.409425, 27.278345),weight: 0.3}
];
heatmap = new google.maps.visualization.HeatmapLayer({
data: data,
radius: 10
});
Run Code Online (Sandbox Code Playgroud)
如您所见,您必须在热图配置中指定半径。
但是如何为热图上的单个源(点)指定不同的半径?
我正在尝试设计一个组件,您可以在其中通过左右移动滑块来更改两个块的宽度比例:

代码和演示:
.outer {
display: flex;
flex-direction: row;
}
.block {
height: 200px;
width: -webkit-calc(50% - 5px);
width: -moz-calc(50% - 5px);
width: calc(50% - 5px);
}
.block-1 {
background-color: red;
}
.block-2 {
background-color: green;
}
.slider {
line-height: 100%;
width: 10px;
background-color: #dee2e6;
border: none;
cursor: e-resize;
}Run Code Online (Sandbox Code Playgroud)
<div id="app">
<div class="outer">
<div class="block block-1">
Block 1
</div>
<div class="slider">
S<br>l<br>i<br>d<br>e<br>r
</div>
<div class="block block-2">
Block 2
</div>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我曾尝试draggable-vue-directive根据滑块位置使用和更改块的宽度。
然而,它并没有很好地工作,因为draggable-vue-directive将滑块设置为position:fixed反过来弄乱了块对齐。 …
我有一个名为new_data.txt的.txt文档.本文档中的所有数据均以点分隔.我想在python中打开我的文件,将其拆分并放入列表中.
output = open('new_data.txt', 'a')
output_list = output.strip().split('.')
Run Code Online (Sandbox Code Playgroud)
但是我有一个错误:
AttributeError: 'file' object has no attribute 'strip'
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
注意:我的程序是在Python 2上
我想从我的html文件中删除所有内容并添加<!DOCTYPE html><html><body>.
到目前为止,这是我的代码:
with open('table.html', 'w'): pass
table_file = open('table.html', 'w')
table_file.write('<!DOCTYPE html><html><body>')
Run Code Online (Sandbox Code Playgroud)
运行我的代码后,table.html现在是空的.为什么?
我该如何解决这个问题?
我acync.series在我的node.js程序上使用.我试图异步循环使用mongoose集合async.each.这是到目前为止的代码:
var async = require('async');
var mongoose = require('mongoose');
var usersData;
async.series([
function(callback) {
mongoose.connect("mongodb://localhost/****");
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error...'));
db.once('open', function callback() {
console.log('db opened!');
});
callback();
},
function(callback) {
users = mongoose.model('User', new mongoose.Schema({name: String,age: Number}));
users.find(function(err, userFound) {
if (err) {console.log(err);}
usersData = userFound;
});
callback();
},
function(callback) {
async.each(usersData, function(userData, callback) {
some code....
}, callback);
}
])
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我从异步中得到以下错误:
if (!arr.length) {
^
TypeError: Cannot read property 'length' of …Run Code Online (Sandbox Code Playgroud) 我想创建一个类似于这个的地图:

此示例显示了世界范围的温度水平.但我需要使用自己的非温度数据来表示污染程度.
我尝试了"热图"图层,但它对我不起作用,因为它主要用于表示人口水平:

如何使用Bing或Google maps api创建这样的"温度图"?
如果没有使用Google或Bing api的原生解决方案,是否有可以帮助我的东西派对库?