gpt4 book ai didi

r - a * b * y : non-conformable arrays 中的错误

转载 作者:行者123 更新时间:2023-12-05 00:25:21 24 4
gpt4 key购买 nike

关闭。这个问题需要debugging details .它目前不接受答案。












想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。

7年前关闭。




Improve this question



Cold <- matrix(c(1.89,3.76,2.47,4.76),2,2,byrow=TRUE)
X <- matrix(c(0,2,2,4,3,6),3,2,byrow=TRUE)
y <- matrix(c(1,5,6))

m <- 2;
R <- 2;
Ec <- 0.001;
p <- 1/(m-1)

C <- mat.or.vec(R,R)
M <- length(X[,1])
mu <- mat.or.vec(M,R)
#mu=matrix(,M,R)
Q1=0;Q2=0;
pl <- 1/(m-1)
F=0;
it <- 0;
ph <- 1;


repeat
{




####################
for (i in 1:M)
{
for (j in 1:R)
{
Q1=0;Q2=0;F=0
Q1 <- sum((X[i,]-Cold[j,])^2)
for (k in 1:R)
{
Q2 <- sum((X[i,]-Cold[k,])^2)
F=Q1/Q2+F
}
mu[i,j] <- solve(F)
}
}


####################






##########centre Update
B=mat.or.vec(1,2);
for (j in 1:R)
{
A=mat.or.vec(1,2);
for (i in 1:M)
{
A=X[i,]*mu[i,j]^m+A

#C=(t(mu)*X)/colSums(mu)
}
B=colSums(mu^m)
C[j,] <- A/B[j];
}
#########centre update end



ph <- abs(sqrt(sum((C - Cold)^2)))
Cold <- C
##################
if(ph < Ec)
{
break;
}
it <- it+1
}
##################


X
plot(X[,1],X[,2],pch=5,lwd=6,col = "blue",cex = .6)
for(i in 1:length(C[,1]))
{
points(C[i,1],C[i,2],pch=4,lwd=4)
}

library(MASS)

w <- rep(1,nrow(X))
X <- cbind(w,X)
X <- as.matrix(X)
para <- mat.or.vec(3,R)
#i<-0

h <- mat.or.vec(3,3)
a <- mat.or.vec(3,3)
b <- mat.or.vec(3,3)
for(i in 1:R)
#while (i<3)
{
h <- t(X)*(diag(mu[,i]))^2*X
a <- solve(t(X)*(diag(mu[,i]))^2*X)
b <- (t(X)*diag(mu[,i])^2)
para[,i] <- a*b*y
}

This is the code for clustering, it clusters the data and it works nice but it gives me >an error in the end part of calculating rule consequents, it is finally taking a toll on >me.It shows the error "Error in a * b * y : non-conformable arrays", Can anyone help me >please?

最佳答案

短语“一致数组”是线性代数行话,意思是“可以一起操作的数组”。

例如,如果要将两个数组相加,则它们的大小需要相同。

事实上,由于标准数学运算符,+ , - , * , / , ^等操作逐个元素,您总是需要数组(或矩阵)具有相同的大小。

对于(内部)矩阵乘法,%*% ,第一个矩阵中的列数必须与第二个矩阵中的行数相同。

关于r - a * b * y : non-conformable arrays 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24684623/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com