我有以下3x3方阵a和矢量x:
a = matrix(c(1.0, 0.1, 0.5,
0.1, 1.0, 0.9,
0.5, 0.9, 1.0), nrow=3, ncol=3)
x = c(0.1,0.2,0.3)
Run Code Online (Sandbox Code Playgroud)
我想基本上使用矩阵和向量的上三角形来遵循公式
y = (a12 - (x1/x2)^2 + (a13 - x1/x3)^2 + (a23 - x2/x3)^2
Run Code Online (Sandbox Code Playgroud)
我在上面的公式中使用了以下用于R的循环,我收到以下错误:
Error in a[i, j] : subscript out of bounds
Run Code Online (Sandbox Code Playgroud)
如果你能做错什么事我能不能告诉我,我将不胜感激.
## initialize y
y = 0
for (i in 1 : nrow(a)-1){
for (j in i+1 : nrow(a)){
y = y + ((a[i,j]) - (x[i]/x[j])^2
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个由字符串和整数组成的列表.我必须只弹出整数并将其放在一个单独的列表中.我的代码:
list1=['a','b','c','d','e','f','g','h',1,2,3]
list=[]
x=0
for i in list1:
if isinstance(i,int) :
list.append(i)
list1.pop(x)
x += 1
print(list1)
print(list)
Run Code Online (Sandbox Code Playgroud)
输出上述代码
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 2]
[1, 3]
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么我的代码没有删除所有整数?我的代码出了什么问题?
我正在尝试将 Google 地图 API 集成到我的页面。我使用从 JSON 中提取位置并将该位置保存在数组中的代码,然后返回每个位置的位置数据。一切都很顺利,只是我infowindow在点击地图上的标记时无法激活该功能。这是点击时出现的错误:
var map; // declares a global map variable
/*
Start here! initializeMap() is called when page is loaded.
*/
function initializeMap() {
var locations;
var mapOptions = {
disableDefaultUI: true
};
/*
For the map to be displayed, the googleMap var must be
appended to #mapDiv in resumeBuilder.js.
*/
map = new google.maps.Map(document.querySelector('#map'), mapOptions);
/*
locationFinder() returns an array of every location string from the JSONs
written for bio, education, and …Run Code Online (Sandbox Code Playgroud)我想用我的训练数据集的修改版本运行我的随机森林。我的训练数据包含不同的列,其中一列attribute使用 0-6 的值调用。我的想法是只删除0并使用以下代码保留其余部分:
training_data4 <- training_data3[!training_data3$attribute == "0", ]
Run Code Online (Sandbox Code Playgroud)
但是,当我使用训练数据运行随机森林时,我收到以下错误消息:
rf200 <- randomForest(attribute ~ ., data=training_data4, importance=T,
proximity=F, ntree=200 )
Run Code Online (Sandbox Code Playgroud)
randomForest.default(m, y, ...) 中的错误:y 中不能有空类
我已经知道我的 肯定有问题training_data4,因为我已经用我的原始训练集尝试过它并且没有这个问题。