昨天,我尝试了一些网站MOOC,其中涉及一些方案拟定任务。 我正试图解决一个容易的问题,但我无法理解为什么我仍会遇到这样的错误:
In [32]: import A1Part3
File "A1Part3.py", line 26
t = np.arrange(x.size/N)
^
IndentationError: unexpected indent
I do not understand why, I was reading about python indentation, and as far I know if some statement is indented inside the block above it should consider part of that function. I don t know what I m doing wrong or what I am misunderstanding.
"""
A1-Part-3: Python array indexing
Write a function that given a numpy array x, returns every Nth element in x, starting from the
first element.
The input arguments to this function are a numpy array x and a positive integer N such that N < number of
elements in x. The output of this function should be a numpy array.
If you run your code with x = np.arange(10) and N = 2, the function should return the following output:
[0, 2, 4, 6, 8].
"""
import numpy as np
def hopSamples(x,N):
"""
Inputs:
x: input numpy array
N: a positive integer, (indicating hop size)
Output:
A numpy array containing every Nth element in x, starting from the first element in x.
"""
## Your code here
t = np.arrange(x.size/N)
cont = 0
i = 0
while cont<x.size :
cont+=N
t[i]=x[cont]
i=i+1
return t