anonymous
  • anonymous
Is there a way for me to access only certain elements in a 2D array, for example the vertical elements only or the first elements in a set of ordered pairs, in Python?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
2D arrays? you mean lists of lists, or python's array module, or do you mean numpy's arrays?
anonymous
  • anonymous
lists of lists: A = [[1,0,0], [0,1,0], [0,0,1]] if you only want to get out the 'columns' then you can transpose it using list comprehensions.
anonymous
  • anonymous
or you can simply loop: col2 = [] for row in A: col2.append(row[1]) # gets out the elements in the 2nd "column"

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
list comprehensions: col2 = [row[1] for row in A]
anonymous
  • anonymous
sets of ordered pairs? you mean Python's native set() ?

Looking for something else?

Not the answer you are looking for? Search for more explanations.