In [1]:
import numpy as np

In [2]:
x = np.arange(10)
y = np.arange(10)

In [3]:
x + y


Out[3]:
array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])

In [4]:
x + 6


Out[4]:
array([ 6,  7,  8,  9, 10, 11, 12, 13, 14, 15])

In [5]:
x = np.arange(12).reshape(3,4)
y = 2*np.arange(12).reshape(3,4)

In [6]:
x + y


Out[6]:
array([[ 0,  3,  6,  9],
       [12, 15, 18, 21],
       [24, 27, 30, 33]])

In [7]:
x.shape


Out[7]:
(3, 4)

In [8]:
y.shape


Out[8]:
(3, 4)

In [9]:
x


Out[9]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

In [14]:
z = np.arange(4)
z


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

In [15]:
x + z


Out[15]:
array([[ 0,  2,  4,  6],
       [ 4,  6,  8, 10],
       [ 8, 10, 12, 14]])

In [16]:
x.shape, z.shape


Out[16]:
((3, 4), (4,))

In [17]:
z2 = np.arange(3)
z2


Out[17]:
array([0, 1, 2])

In [18]:
x + z2


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-9b500e1856f1> in <module>()
----> 1 x + z2

ValueError: operands could not be broadcast together with shapes (3,4) (3,) 

In [19]:
x + z2[:, np.newaxis]


Out[19]:
array([[ 0,  1,  2,  3],
       [ 5,  6,  7,  8],
       [10, 11, 12, 13]])

In [21]:
x + z2[:, None]


Out[21]:
array([[ 0,  1,  2,  3],
       [ 5,  6,  7,  8],
       [10, 11, 12, 13]])

In [31]:
x + z2[None, :]


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-dc77339e598b> in <module>()
----> 1 x + z2[None, :]

ValueError: operands could not be broadcast together with shapes (3,4) (1,3) 

In [33]:
z2[None, :].shape


Out[33]:
(1, 3)

In [22]:
z2.shape


Out[22]:
(3,)

In [24]:
print(z2[:, None])


[[0]
 [1]
 [2]]

In [28]:
x.shape


Out[28]:
(3, 4)

In [30]:
z2[:, None, None].shape


Out[30]:
(3, 1, 1)

In [35]:
import os

In [36]:
os.environ['DROPBOX']


Out[36]:
'/Users/tdm/Dropbox'

In [37]:
os.environ['PATH']


Out[37]:
'/Users/tdm/lsst_setup:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/Users/tdm/bin:/Users/tdm/anaconda/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin'

In [39]:
os.environ['ROBOAODIR'] + '/my/datafile'


Out[39]:
'/Users/tdm/Dropbox/kepler/data/roboao/my/datafile'

More strings!


In [40]:
for x in range(10):
    print(x)


0
1
2
3
4
5
6
7
8
9

In [44]:
for x in 'abcdefgh':
    print(x)


a
b
c
d
e
f
g
h

In [49]:
x = 3; y = 4.12512

In [52]:
'x is {0:.3f}, y is {1:.1f}!'.format(x, y)


Out[52]:
'x is 3.000, y is 4.1!'

In [53]:
l = [1,3,5,7,9]
'index 2 of l is {0[2]}, index 4 is {0[4]}'.format(l)


Out[53]:
'index 2 of l is 5, index 4 is 9'

In [55]:
d = dict(a=2, b=3)
'check out this value: {0[a]}'.format(d)


Out[55]:
'check out this value: 2'

In [60]:
import re

s = 'abcb124cde'

m = re.search('b\d+', s)
if m:
    print('yes!')


yes!

In [61]:
m.group(0)


Out[61]:
'b124'

In [64]:
s = 'okj?okl,'

m = re.search('\w+', s)
m.group(0)


Out[64]:
'okj'

In [ ]: