In [4]:
import numpy as np

In [10]:
a = np.array( [ [1,0,2,4,3] , [7,2,3,1,4] ] )

In [11]:
a


Out[11]:
array([[1, 0, 2, 4, 3],
       [7, 2, 3, 1, 4]])

In [14]:
np.flip(a,1)


Out[14]:
array([[3, 4, 2, 0, 1],
       [4, 1, 3, 2, 7]])

In [1]:
CAR_COLORS_NO_HASH = ['7FFF00', '7FFFD4', 'D2691E', '8B008B', 'BDB76B',\
                      '8B0000', 'FF1493', '1E90FF', 'FFD700', 'ADFF2F', \
                      'CD5C5C', 'F0E68C']

In [2]:
with_hash = ['#'+x for x in CAR_COLORS_NO_HASH]
with_hash


Out[2]:
['#7FFF00',
 '#7FFFD4',
 '#D2691E',
 '#8B008B',
 '#BDB76B',
 '#8B0000',
 '#FF1493',
 '#1E90FF',
 '#FFD700',
 '#ADFF2F',
 '#CD5C5C',
 '#F0E68C']

In [6]:
arr = np.resize(np.arange(36),[6,6])

In [7]:
arr


Out[7]:
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20, 21, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])

In [29]:
np.flip(arr,1)


Out[29]:
array([[ 5,  4,  3,  2,  1,  0],
       [11, 10,  9,  8,  7,  6],
       [17, 16, 15, 14, 13, 12],
       [23, 22, 21, 20, 19, 18],
       [29, 28, 27, 26, 25, 24],
       [35, 34, 33, 32, 31, 30]])

In [20]:
arr[:,2]


Out[20]:
array([ 2,  8, 14, 20, 26, 32])

In [26]:
?np.flip

In [30]:
import sqlite3

In [36]:
conn = sqlite3.connect('rush_hour.db')

In [37]:
cur = conn.cursor()

In [38]:
sql = 'select count(1) from segment where num_v_cars = 4 and num_h_cars=2 and num_v_trucks=0 and num_h_trucks=1'

In [39]:
sql


Out[39]:
'select count(1) from segment where num_v_cars = 4 and num_h_cars=2 and num_v_trucks=0 and num_h_trucks=1'

In [47]:
cur.execute(sql)
count = cur.fetchone()[0]

In [44]:
cur.fetchone()

In [48]:
arr


Out[48]:
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20, 21, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])

In [49]:
x = np.array( [ [1,2,3,4] , [2,3,4,6] ] )
x


Out[49]:
array([[1, 2, 3, 4],
       [2, 3, 4, 6]])

In [58]:
np.size( x[x==3] )


Out[58]:
2

In [60]:
VERTICAL_CAR = int('101',2)
np.size(x[x==VERTICAL_CAR])


Out[60]:
0

In [ ]: