1

Ok, So I have a 2-d array of data which has the shape(23025, 1000), it's called 'allfiles'.

I need to go through the array 50 columns at a time and extract them to a sub-array for manipulation. The problem is when i address the array using the code below, it doesn't seem to recognize the variables (a and b). the code i have at the moment is shown below.

    q = 50
    a = np.shape(allfiles)[1] # a = 1000
    for i in range(a):
        b = a + q
        data = allfiles[:,a:b]

When i replace the variables with number, i.e...

    data = allfiles[:,30:80]

It seems to work. So, my question is - is there a way i can pass variables to the array index? If not is there a better way i can create a subarray using variables?

I have tried to find this problem on stack overflow with no luck, but i'm sure i'm not the first person to have this trouble?

Cheers guys, Morgan

1 Answer 1

2

You are getting i from the loop but don't use it.

q = 50

for start in xrange(0, allfiles.shape[1], q):
    data = allfiles[:,start:start+q]
    ...
Sign up to request clarification or add additional context in comments.

1 Comment

Cheers, that sorted everything out for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.