Skip to main content
deleted 32 characters in body
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

I have an oddly shaped array (it is 100 by 100 by {1 or 3}, with the 1 or 3 being essentially random). I want to run a 'Do' loop on the first 2 dimensions of the array, but I only want to do the thing in the loop when I am at a member with three members in the last dimension. Is there a way to do this? I tried playing with things like If[Array[[i]][[j]][[3]]!=Null,t,f], but to no avail. At the end of the day, what I want is a way to write the following in Mathematica's language:

If Array[[i]][[j]][[3]] exists, then do expr, otherwise, do not do expr.

  • If Array[[i]][[j]][[3]] exists, then do expr

Looking forward to any solutions/advice/ideas! Thanks!.

I have an oddly shaped array (it is 100 by 100 by {1 or 3}, with the 1 or 3 being essentially random). I want to run a 'Do' loop on the first 2 dimensions of the array, but I only want to do the thing in the loop when I am at a member with three members in the last dimension. Is there a way to do this? I tried playing with things like If[Array[[i]][[j]][[3]]!=Null,t,f], but to no avail. At the end of the day, what I want is a way to write the following in Mathematica's language:

If Array[[i]][[j]][[3]] exists, then do expr, otherwise, do not do expr.

Looking forward to any solutions/advice/ideas! Thanks!

I have an oddly shaped array (it is 100 by 100 by {1 or 3}, with the 1 or 3 being essentially random). I want to run a 'Do' loop on the first 2 dimensions of the array, but I only want to do the thing in the loop when I am at a member with three members in the last dimension. Is there a way to do this? I tried playing with things like If[Array[[i]][[j]][[3]]!=Null,t,f], but to no avail. At the end of the day, what I want is a way to write the following in Mathematica's language:

  • If Array[[i]][[j]][[3]] exists, then do expr

Looking forward to any solutions/advice/ideas.

Source Link
Jobo
  • 1
  • 1

How do I use the existence of an array member as an 'If' condition?

I have an oddly shaped array (it is 100 by 100 by {1 or 3}, with the 1 or 3 being essentially random). I want to run a 'Do' loop on the first 2 dimensions of the array, but I only want to do the thing in the loop when I am at a member with three members in the last dimension. Is there a way to do this? I tried playing with things like If[Array[[i]][[j]][[3]]!=Null,t,f], but to no avail. At the end of the day, what I want is a way to write the following in Mathematica's language:

If Array[[i]][[j]][[3]] exists, then do expr, otherwise, do not do expr.

Looking forward to any solutions/advice/ideas! Thanks!