R/unfold.R

Defines functions unfold

Documented in unfold

#' Tensor unfolding
#'
#' @description Performing to multi-dimensional arrays tensor unfolding, also known as matricization
#' @param ten A multi-dimensional array.
#' @param k An integer specifying the mode of array to unfold.
#'
#' @return A matrix
#' @export
#' @import rTensor
#'
#' @examples
#' unfold(array(1:24, dim=c(3,4,2)), 2);
#'
#'
#'
unfold <- function(ten,k){
  if (requireNamespace('rTensor', quietly = TRUE)){
    #a <- rTensor::as.tensor(ten)
    #a <- rTensor::rs_unfold(a, k)
    a <- as.tensor(ten)
    a <- rs_unfold(a, k)
    return(a@data)
  }
}

Try the tensorMiss package in your browser

Any scripts or data that you put into this service are public.

tensorMiss documentation built on May 29, 2024, 2:11 a.m.