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 in Python by ana1504.k
• 7,870 points
13 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 by SDeb
• 13,160 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
19 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
41 views
0 votes
1 answer

Python BeautifulSoup CSS Selector

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

answered May 14 in Python by Jim
38 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 24 in Python by Shabnam
• 920 points
34 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 in Python by Waseem
• 4,480 points
29 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
50 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
103 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 4 in Python by SDeb
• 13,160 points
161 views