Combine selector conditions

0 votes

I want to combine several conditions to select row/columns from an array.

For a matrix A, I know that

A[:, [1,3]] 

gives me the second and fourth column. Also,

A[:, :3]

works like a charm. However, I fail to combine the conditions:

A[:, [:3, 6, 7]]

But this gives me a syntax error. Can anyone tell me how to get this selection going?

Jun 19, 2019 in Python by ana1504.k
• 7,910 points
681 views

1 answer to this question.

0 votes

In a nutshell, you can do:

A[:, range(3) + [6, 7]]

or

A[:, np.r_[:3, 6, 7]]
answered Jun 19, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

Combine list items to a string

>>> stmt = ['this','is','a','statement'] >>> ' '.join(sentence) 'this is ...READ MORE

answered Jun 7, 2018 in Python by Hamartia's Mask
• 1,580 points
641 views
0 votes
1 answer

Use conditional statements to handle multi-line conditions

You don't need to use 4 spaces ...READ MORE

answered Oct 15, 2018 in Python by charlie_brown
• 7,720 points
2,419 views
0 votes
1 answer

Python BeautifulSoup CSS Selector

Yes, you can use the select() method of BeautifulSoup ...READ MORE

answered May 14, 2019 in Python by Jim
1,324 views
0 votes
1 answer

How can I combine two dataframes in Python Pandas?

Hi, You can use the following methods to ...READ MORE

answered Jun 25, 2019 in Python by Shabnam
• 930 points
1,267 views
0 votes
0 answers

Why is selenium css and xpath selector not working?

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or ...READ MORE

Jul 18, 2019 in Python by Waseem
• 4,540 points
2,128 views
+1 vote
2 answers

View onto a numpy array?

 just index it as you normally would. ...READ MORE

answered Oct 18, 2018 in Python by roberto
1,034 views
0 votes
1 answer
0 votes
1 answer

Printing a large numpy array

numpy.set_printoptions(threshold='nan') READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,741 views
0 votes
1 answer

How can i combine flask and nameko?

You absolutely can use nameko and Flask together.  In that ...READ MORE

answered Feb 5, 2019 in Python by SDeb
• 13,300 points
1,424 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP