Ask
your own question, for FREE!
Computer Science
10 Online
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?
Still Need Help?
Join the QuestionCove community and study together with friends!
2D arrays? you mean lists of lists, or python's array module, or do you mean numpy's arrays?
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.
or you can simply loop: col2 = [] for row in A: col2.append(row[1]) # gets out the elements in the 2nd "column"
list comprehensions: col2 = [row[1] for row in A]
sets of ordered pairs? you mean Python's native set() ?
Can't find your answer?
Make a FREE account and ask your own questions, OR help others and earn volunteer hours!
Join our real-time social learning platform and learn together with your friends!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
VERNEISH:
Two objects are moving along separate linear paths where each path is described by position, d, and time, t.
Maci:
what are the best stock apps for people who want to start investing?
Twaylor:
genuienly how do i get better self control i keep watcing youtube and theres this
IzzyCookie:
|dw:1792074056138:dw| Uhm, I don't know where to ask this, but I'm in college welding at my community college, and I need help learning vertical welding for
thehearken:
not sure if this is considered spam, im sorry if it is, but does anyone have tips
1 day ago
1 Reply
0 Medals
5 days ago
3 Replies
2 Medals
1 week ago
3 Replies
0 Medals
3 days ago
9 Replies
1 Medal
1 week ago
2 Replies
1 Medal