# Mathematica replaces list of zeros with zero [closed]

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.

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

Easy way...keep stucture of f[ ]
g[x_] := {{Im[x], 0 Re[x]}, 0 {Re[x], Im[x]}};