4
$\begingroup$

Consider the following functions:

f[x_]:= {{Im[x], Re[x]}, {Re[x], Im[x]}};

g[x_]:= {{Im[x],0},{0,0}}

When applying each of the functions to the list of lists {{1,2,3}}, it yields the results

{{{{0, 0, 0}, {1, 2, 3}}, {{1, 2, 3}, {0, 0, 0}}}}

{{{{0, 0, 0}, 0}, {0, 0}}}

The problem with the second solution is that some entries are numbers, i.e. 0, even though they should be lists.

Considering that I wish to use something like f /@ listoflists (which means I cannot simply edit each of the lists): how can I obtain a result where instead of 0 there is a list of 0s for all entries of the matrix?

Edit: fixed some typos and made the objective clearer.

$\endgroup$
3
  • $\begingroup$ What do you want for an answer to g[{{1,2,3}}]? $\endgroup$
    – MikeY
    Apr 13, 2022 at 13:52
  • $\begingroup$ @MikeY exactly the same form as if f was used, but with a list of 0s instead of just 0 $\endgroup$
    – miniplanck
    Apr 13, 2022 at 13:53
  • 1
    $\begingroup$ @MikeY I edited the original post. Hope it makes it clearer! $\endgroup$
    – miniplanck
    Apr 13, 2022 at 13:55

1 Answer 1

6
$\begingroup$

Easy way...keep stucture of f[ ]

g[x_] := {{Im[x], 0 Re[x]}, 0 {Re[x], Im[x]}};


g[{{1, 2, 3}}]

(* {{{{0, 0, 0}}, {{0, 0, 0}}}, {{{0, 0, 0}}, {{0, 0, 0}}}} *)
$\endgroup$
1
  • 1
    $\begingroup$ Damn, inexperience really shows in these situations. Thank you kindly! $\endgroup$
    – miniplanck
    Apr 13, 2022 at 14:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.