0

I tried the following codes to get elements of "1 46 91 136".

import numpy as np

x0 = np.arange(0, 180)

y0=x0[1:45:180]

However, y0 is array([1]).

I noticed someone use the following codes: z0=x0[0:91:90]

This results in array([0, 90]). What is the meaning of using "91" which is larger that "90"?

The colon (:) is quite different to that in Matlab code. Would you please give me some suggestions?

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
Erickzhou
  • 5
  • 3

1 Answers1

0

The Syntax for array slices in Python is start:end:step, not start:step:end like MATLAB.

Therefore you want y0=x0[1:180:45].

import numpy as np    
x0 = np.arange(0, 180)    
y0=x0[1:180:45]
print(y0)
>>> [  1  46  91 136]
Loocid
  • 6,112
  • 1
  • 24
  • 42