In [14]:
import numpy as np
B = np.arange(3)
print B
#print np.exp(B)
print np.sqrt(B)


[0 1 2]
[ 0.          1.          1.41421356]

In [26]:
#Return the floor of the input
a = np.floor(10*np.random.random((3,4)))
#print a

#a.shape
## flatten the array
#print a.ravel()
#a.shape = (6, 2)
#print a 
#print a.T
print a.resize((2,6))
print a

#If a dimension is given as -1 in a reshaping operation, the other dimensions are automatically calculated:
#a.reshape(3,-1)


None
[[ 9.  7.  6.  4.  9.  0.]
 [ 2.  9.  1.  3.  4.  0.]]

In [32]:
a = np.floor(10*np.random.random((2,2)))
b = np.floor(10*np.random.random((2,2)))
print a
print '---'
print b
print '---'
print np.hstack((a,b))
#np.hstack((a,b))


[[ 5.  6.]
 [ 1.  5.]]
---
[[ 8.  6.]
 [ 9.  0.]]
---
[[ 5.  6.  8.  6.]
 [ 1.  5.  9.  0.]]

In [37]:
a = np.floor(10*np.random.random((2,12)))
#print a
#print np.hsplit(a,3)
#print np.hsplit(a,(3,4))   # Split a after the third and the fourth column
a = np.floor(10*np.random.random((12,2)))
print a
np.vsplit(a,3)


[[ 5.  2.]
 [ 1.  3.]
 [ 9.  6.]
 [ 2.  2.]
 [ 7.  2.]
 [ 8.  2.]
 [ 1.  7.]
 [ 2.  8.]
 [ 4.  4.]
 [ 8.  5.]
 [ 4.  3.]
 [ 2.  3.]]
Out[37]:
[array([[ 5.,  2.],
        [ 1.,  3.],
        [ 9.,  6.],
        [ 2.,  2.]]), array([[ 7.,  2.],
        [ 8.,  2.],
        [ 1.,  7.],
        [ 2.,  8.]]), array([[ 4.,  4.],
        [ 8.,  5.],
        [ 4.,  3.],
        [ 2.,  3.]])]

In [40]:
#Simple assignments make no copy of array objects or of their data.
a = np.arange(12)
b = a
# a and b are two names for the same ndarray object
b is a
b.shape = 3,4
print a.shape
print id(a)
print id(b)


(3, 4)
82691200
82691200

In [43]:
#The view method creates a new array object that looks at the same data.
c = a.view()
c is a
c.shape = 2,6
#print a.shape
c[0,4] = 1234
a


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

In [46]:
#The copy method makes a complete copy of the array and its data.
d = a.copy() 
d is a
d[0,0] = 9999
print d 
print a


[[9999    1    2    3]
 [1234    5    6    7]
 [   8    9   10   11]]
[[   0    1    2    3]
 [1234    5    6    7]
 [   8    9   10   11]]

In [ ]: