0

If I have a matrix like:

M = [[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]

And I have a function like:

def expand(v: int) -> Tuple[Tuple[float, float], Tuple[float, float]]:
    return [[1.1, 2.2], [3.3, 4.4]]

or some arbitrary mapping to a square matrix, how could I apply this function to the existing matrix so the output is still a valid 2 dimensional matrix?

So I'd like the output matrix to be something like a flatmap where the output is a 6 x 6 matrix and not a 3 x 3 x 2 x 2 matrix.

Rob
  • 3,333
  • 5
  • 28
  • 71
  • Have you considered using numpy: https://numpy.org/doc/stable/user/whatisnumpy.html – Tzane Sep 13 '21 at 06:11
  • yes, but i'm not sure that resize will always work – Rob Sep 13 '21 at 07:21
  • and I'd like to write an algorithm from scratch for this – Rob Sep 13 '21 at 07:21
  • Alright, could you elaborate a bit more on what you want to do? If you want to apply a function on each item in the matrix, you have to perform some sort of loop on your nested list, something like this: https://stackoverflow.com/questions/34080828/map-a-nested-list-in-python – Tzane Sep 13 '21 at 07:50

0 Answers0