Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I want to delete any column in my python array that has a number less than 2 in

ID: 3553363 • Letter: I

Question

I want to delete any column in my python array that has a number less than 2 in it. How do I go about doing this?

I have created an array using python like this:


import numpy as np

vecs=np.zeros((20,3))


for i in range(20):

for j in range(3):

vecs[i][0]=i+2

vecs[j][0]=j+2

vecs[i][1]= i+1

vecs[j][1]=j+1

vecs[i][2]=i+5

vecs[j][2]=j+5

print vecs


output

:[[ 2. 1. 5.]

[ 3. 2. 6.]

[ 4. 3. 7.]

[ 5. 4. 8.]

[ 6. 5. 9.]

[ 7. 6. 10.]

[ 8. 7. 11.]

[ 9. 8. 12.]

[ 10. 9. 13.]

[ 11. 10. 14.]

[ 12. 11. 15.]

[ 13. 12. 16.]

[ 14. 13. 17.]

[ 15. 14. 18.]

[ 16. 15. 19.]

[ 17. 16. 20.]

[ 18. 17. 21.]

[ 19. 18. 22.]

[ 20. 19. 23.]

[ 21. 20. 24.]]


so the entire second column should be deleted.How do i do this?

Explanation / Answer

Nested list comprehensions is what you need. Example:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote