NanoComp / mpb

MIT Photonic-Bands: computation of photonic band structures in periodic media
GNU General Public License v2.0
165 stars 89 forks source link

Arguments for field arrays in MPB Data Analysis #115

Closed JohnWeiner closed 4 years ago

JohnWeiner commented 4 years ago

Here are a couple of lines from the Data Analysis MPB tutorial: for f in efields:

Get just the z component of the efields

f = f[..., 0, 2]

This is undoubtedly a rookie question, but what does the 0 argument mean? I presume the last argument, 2, is the axis (x->0, y->1, z->2), but I have not been able to find the meaning of the next-to-last argument in the read-the-docs documentation of the MPBArray or get functions or Googled documentation (StackOverflow, etc.) on numpy array attributes.

stevengj commented 4 years ago

It's the same as f[:, :, 0, 2]. f is a 4d array (X x Y x Z x 3), where the Z direction has only 1 pixel (since this is a 2d calculation), so by passing 0 for the Z index we are taking the 2d (X x Y) slice corresponding to Ez (2).

JohnWeiner commented 4 years ago

Thanks, got it. I didn’t know about the Ellipse object or the multidimensional indexing. Much clearer now.

On Jun 16, 2020, at 17:50, Steven G. Johnson notifications@github.com wrote:

It's the same as f[:, :, 0, 2]. f is a 4d array (X x Y x Z x 3), where the Z direction has only 1 pixel (since this is a 2d calculation), so by passing 0 for the Z index we are taking the 2d (X x Y) slice corresponding to Ez (2).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NanoComp/mpb/issues/115#issuecomment-644850634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4DU6HUTCBWWANWVA4D35TRW6IFJANCNFSM4N53EJAA.