1

I am trying to create an array that is with dimensions:

a(Days,Hours,Station)

I have hourly data for array 'a' for 2 stations over 61 days so currently I have this array with these dimensions:

a(1464,2)

Where the 1464 is the number of hourly data points per station that I have (24 hours*61 days). However I want to break it down even further and add another dimension that has Days so the dimensions would then be:

a(61 days,24 hours/day, 2 stations)

Any ideas on how I would correctly be able to take the array 'a' that I currently have and change it into these 3 dimensions?

2
  • a is numpy array or standard array? Commented Jul 5, 2016 at 21:14
  • a is a numpy array. Commented Jul 5, 2016 at 21:51

3 Answers 3

1

This will split array a to chunks with maximum length size.

def chunks( a, size ):
    arr = iter( a )
    for v in arr:
        tmp = [ v ]
        for i,v in zip( range( size - 1 ), arr ):
            tmp.append( v )

        yield tmp

splitted = list( chunks( a, 24 ) )
Sign up to request clarification or add additional context in comments.

5 Comments

Oh ok interesting. I suppose I could do this then. I also read about np.rearrage(a, (61,2,2)) so I tried that but I don't exactly know what the function is doing behind the scenes. Are you familiar with this? Would this be an easy solution too?
Also this doesn't quite work. Splitted is of dimensions (1,2,1464) instead of (61,24,2) like I want.
Can't find any info on np.rearrage. Don't know anything abount it.
Is it possible that shape of a is (2, 1464)? It's only possible reason, that i can find, that would lead to (1, 2, 1646).?
Yes that is why! So I need to switch the dimensions around somehow and then if I do that and use this code it works. Thanks! Meghan
1

You could try to make a 61x24x2 array. This should work:

b = []
for i in xrange(61):
    b.append(a[i*61:(i+1)*61])

Comments

0

If you're first field is hours * days, a transformation would simply be: a(x, y) => a(x // 24, x % 24, y)

x // 24 is floor division so 1500 // 24 = 62, the days. You did not specify, but I assume the "Hours" field would be the remaining hours; so x % 24 gets the remaining hours, and 1500 % 25 = 12, the number of hours. Lastly, the station field remains the same.

I don't think you can modify the structure of a list/array in Python, so you would need to create a new one. I'm also not sure if you're actually using the built-in list or the array. I'm not too familiar with the array class so this isn't a complete answer, but I hope it points you in the right direction arithmetically.

Comments

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.