## How to write A[1:2:9](Matlab) in Python

This is the place for queries that don't fit in any of the other categories.

### How to write A[1:2:9](Matlab) in Python

Hi....
i have in matlab this matrix A=[1 2 3;4 5 6;7 8 9] if i type A[1:2:9] the answer is [1 3 5 7 9].....
i read some tutorial on internet, i learnt how to write A(i,:) or A(:,j) in python but i don't know how to write A[1:2:9]...
could you help me??
anastasi.fr

Posts: 22
Joined: Fri Oct 18, 2013 10:17 am

### Re: How to write A[1:2:9](Matlab) in Python

i find the solution:
if i have an array u0=array([[1],[2],[3],[4],[5],[6],[7],[8],[9],[0]])
the command-------> u0.flatten()[from:to:step] like this u0.flatten()[0:6:2] give this answer, 1 3 5 7.....
anastasi.fr

Posts: 22
Joined: Fri Oct 18, 2013 10:17 am

### Re: How to write A[1:2:9](Matlab) in Python

Like this?
Code: Select all
`>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]>>> print x[::2][1, 3, 5, 7, 9]`
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

### Re: How to write A[1:2:9](Matlab) in Python

no....with your code you start from 1-position and step by 2 you arrive at the end of the array....in the other way you could define the stop point inside matrix...
anastasi.fr

Posts: 22
Joined: Fri Oct 18, 2013 10:17 am

### Re: How to write A[1:2:9](Matlab) in Python

You can define start and end as well:
Code: Select all
`>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9]>>> print x[2:6:2][3, 5]`
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe