Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

Convenient way to declare 2D (or even higher dimension) arrays with std::array

You can use a type alias template: #include <array> #include <cstddef> template <class T, std::size_t x, std::size_t y> using Array2D = std::array<std::array<T, y>, x>; int main() { Array2D<int, 5, 3> arr; } You can also generalize it like so for any dimension: #include <array> #include <cstddef> template <class T, std::size_t size, std::size_t… sizes> struct ArrayHelper … Read more

Difference between tensor.permute and tensor.view in PyTorch?

Input In [12]: aten = torch.tensor([[1, 2, 3], [4, 5, 6]]) In [13]: aten Out[13]: tensor([[ 1, 2, 3], [ 4, 5, 6]]) In [14]: aten.shape Out[14]: torch.Size([2, 3]) torch.view() reshapes the tensor to a different but compatible shape. For example, our input tensor aten has the shape (2, 3). This can be viewed as … Read more