English 中文(简体)
a 建筑Tensor, 而不是可变 Sizized 阵列
原标题:Building a Tensor instead of a Variable Sized Array

因此,这里的瘦子:

  1. 想象一个魔方; 它为 3x3x3 。 我碰巧有一个数组, 是一个正立方的魔方, 只有它为 4x4xn。 n 开始为 1

  2. 当数组中每个 4x4 矩阵中的某个条件是真实的时, 矩阵会自我复制; 也就是 n 增长 1 (数组, 或 rebik s 立方体会长/ 变成 幼崽 ) 。 例如, 对于数组中每个 4x4 矩阵, 如果 [2, 4] & gt; [2, 1], 那么矩阵会复制数组中另一个版本 。

  3. 当数组中每个 4x4 矩阵中的相同条件为假时, 矩阵本身就“ 底部” 或将自己抹去。 数组, 或rebik s 立方体会变短 。 比方说, 对于数组中的每个 4x4 矩阵, 如果 [2, 4] & lt; [2, 1), 则矩阵将自己从数组中抹去 。

  4. 于是我试图将这个构建成一个阵列, 显然你不能从一个阵列随意添加和下降矩阵。

  5. 我被告知你必须建一个高压器(从我的概念模型到维基百科说,这看起来像是第二顺序的压力。 )我不是物理学家,绝对不是数学纯净主义者。我是一个基本的应用数学家(OSA ), 但我没有任何程度的数学家,只是几年的“分析”经验。

  6. 希望各位能理解, 如何在R区建立我认为我所写的那种R区, 很难找到可理解的/概念性信息。

非常感谢你们能提供的一切帮助。

我对此非常感谢。

下面是我尝试过的一些东西:

cells<-c(0,.4,0,0,.25,.6,.25,.5,4,12,4,10,20,0,0,0)
Mu<-matrix(cells, 4,4, byrow=TRUE)
Ma<-list(Mu)
for(i in Ma){
    if(i[2,4] > i[2,1]){
       j <-length(Ma) + 1
       c[Ma, j<-Mu]
    }else if(i[2,4] < i[2,1]){
        Ma[[i]] <- NULL
        }
    }
}

这不管用

最佳回答

Since you need to be able to add or remove 4*4 matrices from your array, it may be easier to use a list of 4*4 matrices, instead of an array.

# Initial data
d <- replicate(3, matrix(sample(1:16),4,4), simplify=FALSE)
# Remove an element
remove <- function(d, i) {
  d[[i]] <- NULL
  d
}
# Duplicate an element
duplicate <- function(d, i) {
  d <- append(d, list(d[[i]]))
  d
}
# Example
d <- remove(d, 1)
d <- duplicate(d, 2)
d <- remove(d, 1)
d

If performance is an issue (the list is copied again and again), you may prefer to use an environment instead.

# Sample data
d <- replicate(3, matrix(sample(1:16),4,4), simplify=FALSE)
names(d) <- as.character(seq_along(d))
e <- as.environment(d)
# Remove an element
remove <- function(e, i) {
  rm(list=as.character(i), envir=e)
  e
}
# Duplicate an element
duplicate <- function(e, i) {
  stopifnot( length(ls(e)) > 0 )
  j <- max( as.numeric(ls(e)) ) + 1
  assign( as.character(j), get( as.character(i), envir=e ), envir=e )
  e
}
# Example (the elements are named, and their names do not change)
remove(e, 1)
duplicate(e, 3)
remove(e, 2)
as.list(e)

加上你们重复和搬运的条件,这便成为:

# Sample data
d <- replicate(3, matrix(sample(1:16),4,4), simplify=FALSE)
names(d) <- as.character(seq_along(d))
e <- as.environment(d)
# Main loop
for(i in ls(e)) {      # i is the name of the matrix
  m <- get(i, envir=e) # The matrix itself
  if(m[2,4] > m[2,1]) {
    cat("Duplicating", i, "
")
    duplicate(e, i)
  } else {
    cat("Removing", i, "
")
    remove(e, i)
  }
}
as.list(e)
问题回答

暂无回答




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签