Tensorex.fetch

You're seeing just the function fetch, go back to Tensorex module for more information.
Link to this function

fetch(tensorex, indices)

View Source

Specs

fetch(t(), [integer() | Range.t(), ...]) :: {:ok, t() | number()} | :error

Returns a tensor or a number stored at the index.

The key can be a list of indices or ranges. If integer indices are given, it returns a tensor or a numeric value specified by the index. If ranges are given, it returns a tensor consisting partial elements.

Negative indices are counted from the end.

iex> Tensorex.from_list([[[ 1   ,   -3.1,   2  ],
...>                      [ 4   ,    5  ,  -6.1],
...>                      [ 0.9 ,  -91.2,  11  ]],
...>                     [[10   ,  -30.1,  20  ],
...>                      [40   ,   50  , -60.1],
...>                      [ 0.09, -910.2, 110  ]]])[[0, 0, 0]]
1

iex> Tensorex.from_list([[[ 1   ,   -3.1,   2  ],
...>                      [ 4   ,    5  ,  -6.1],
...>                      [ 0.9 ,  -91.2,  11  ]],
...>                     [[10   ,  -30.1,  20  ],
...>                      [40   ,   50  , -60.1],
...>                      [ 0.09, -910.2, 110  ]]])[[0, 0]]
%Tensorex{data: %{[0] => 1, [1] => -3.1, [2] => 2}, shape: [3]}

iex> Tensorex.from_list([[[ 1   ,   -3.1,   2  ],
...>                      [ 4   ,    5  ,  -6.1],
...>                      [ 0.9 ,  -91.2,  11  ]],
...>                     [[10   ,  -30.1,  20  ],
...>                      [40   ,   50  , -60.1],
...>                      [ 0.09, -910.2, 110  ]]])[[0]]
%Tensorex{data: %{[0, 0] => 1  , [0, 1] =>  -3.1, [0, 2] =>  2  ,
                  [1, 0] => 4  , [1, 1] =>   5  , [1, 2] => -6.1,
                  [2, 0] => 0.9, [2, 1] => -91.2, [2, 2] => 11  }, shape: [3, 3]}

iex> Tensorex.from_list([[[ 1   ,   -3.1,   2  ],
...>                      [ 4   ,    5  ,  -6.1],
...>                      [ 0.9 ,  -91.2,  11  ]],
...>                     [[10   ,  -30.1,  20  ],
...>                      [40   ,   50  , -60.1],
...>                      [ 0.09, -910.2, 110  ]]])[[2]]
nil

iex> Tensorex.from_list([[ 1,  2,  3],
...>                     [ 4,  5,  6],
...>                     [ 7,  8,  9],
...>                     [10, 11, 12]])[[1..2]]
%Tensorex{data: %{[0, 0] => 4, [0, 1] => 5, [0, 2] => 6,
                  [1, 0] => 7, [1, 1] => 8, [1, 2] => 9}, shape: [2, 3]}

iex> Tensorex.from_list([[ 1,  2,  3],
...>                     [ 4,  5,  6],
...>                     [ 7,  8,  9],
...>                     [10, 11, 12]])[[-2..-1]]
%Tensorex{data: %{[0, 0] =>  7, [0, 1] =>  8, [0, 2] =>  9,
                  [1, 0] => 10, [1, 1] => 11, [1, 2] => 12}, shape: [2, 3]}

iex> Tensorex.from_list([[ 1,  2,  3],
...>                     [ 4,  5,  6],
...>                     [ 7,  8,  9],
...>                     [10, 11, 12]])[[1..2, 1..-1]]
%Tensorex{data: %{[0, 0] => 5, [0, 1] => 6,
                  [1, 0] => 8, [1, 1] => 9}, shape: [2, 2]}

iex> Tensorex.from_list([[ 1,  2,  3],
...>                     [ 4,  0,  6],
...>                     [ 7,  8,  9],
...>                     [10, 11, 12]])[[1, 1]]
0.0