Inverse image of arbitrary union

I would like to prove that

$$f^{-1}( \cup_{i \in \mathcal{I} }Y_i) = \cup_{i \in \mathcal{I}}f^{-1}(Y_i)$$

$f$ is a function on Euclidean space from $\mathcal{R}^N$ to $\mathcal{R}^M$. $f^{-1}$ is its inverse. $Y_i$ is an arbitrary set in $\mathcal{R}^M$. $\mathcal{I}$ is an arbitrary index set.

-

It doesn’t really matter what the domain and codomain of $f$ are: the result is true in general. You can prove it in the usual way: show that any element of the lefthand side is an element of the righthand side, and vice versa. I’ll do one direction and leave the other to you.
Suppose that $x\in f^{-1}\left[\bigcup_{i\in\mathcal{I}}Y_i\right]$; then $f(x)\in\bigcup_{i\in\mathcal{I}}Y_i$. By the definition of union there is some $i_0\in\mathcal{I}$ such that $f(x)\in Y_{i_0}$. But then $x\in f^{-1}[Y_{i_0}]\subseteq\bigcup_{i\in\mathcal{I}}f^{-1}[Y_i]$, and since $x\in f^{-1}\left[\bigcup_{i\in\mathcal{I}}Y_i\right]$ was arbitrary, it follows that $$f^{-1}\left[\bigcup_{i\in\mathcal{I}}Y_i\right]\subseteq\bigcup_{i\in\mathcal{I}}f^{-1}[Y_i]\;.$$