rray_squeeze() is conceptually similar to base::drop(), but it allows
for the specification of specific dimensions to squeeze.
rray_squeeze(x, axes = NULL)
| x | A vector, matrix, array or rray. |
|---|---|
| axes | An integer vector specifying the size 1 dimensions to drop. If
|
x with the axes dropped, if possible.
The dimension name handling of rray_squeeze() is essentially identical to
drop(), but some explanation is always helpful:
Dimension names are removed from the axes that are squeezed. So squeezing
a (2, 1, 2) object results in a (2, 2) object using the dimension names
from the original first and third dimensions.
When all dimensions are squeezed, as in the case of (1, 1, 1), then
the first dimension names that are found are the ones that are used in the
(1) result.
#> <rray<int>[10]> #> [1] 1 2 3 4 5 6 7 8 9 10# Multiple squeezed dimensions # (10, 1, 1) -> (10) y <- rray_reshape(x, c(10, 1, 1)) rray_squeeze(y)#> <rray<int>[10]> #> [1] 1 2 3 4 5 6 7 8 9 10# Use `axes` to specify dimensions to drop # (10, 1, 1) -> drop 2 -> (10, 1) rray_squeeze(y, axes = 2)#> <rray<int>[,1][10]> #> [,1] #> [1,] 1 #> [2,] 2 #> [3,] 3 #> [4,] 4 #> [5,] 5 #> [6,] 6 #> [7,] 7 #> [8,] 8 #> [9,] 9 #> [10,] 10# Dimension names are kept here # (10, 1) -> (10) x <- rray_set_row_names(x, letters[1:10]) rray_squeeze(x)#> <rray<int>[10]> #> a b c d e f g h i j #> 1 2 3 4 5 6 7 8 9 10#> <rray<int>[10]> #> a b c d e f g h i j #> 1 2 3 4 5 6 7 8 9 10