In [2]:
import numpy as np
In [3]:
x=np.zeros((3,4,5))
1D called vector 2D called matrix 3D nad so on tensor
In [4]:
print x
In [5]:
type(x)
Out[5]:
In [6]:
y=np.ones((2,3))
In [7]:
print y
I need a matrix like this
[[2,3],
[4,5],
[6,7]]
In [8]:
z=np.arange(2,8,1)
alpha=np.reshape(z,(3,2))
print alpha
In [9]:
beta= np.random.randn(3,4)
print beta
In [10]:
gamma=beta*2.0
print gamma
In [11]:
a=[3,4,5]
a=np.array(a)
type(a)
Out[11]:
np array operator
In [12]:
a=np.random.randint(0,10,(2,3))
b=np.random.randint(0,10,(2,3))
print a
print b
In [13]:
print "element-wise addition:\n%s"%(a + b)
In [14]:
print "element-wise addition:\n%s"%(a * b)
In [15]:
print a
print b.T
print '-----'
print np.dot(a,b.T)
Sliccing
In [16]:
a=np.random.randint(0,10,(4,5))
print a
In [17]:
a[0,2]
Out[17]:
In [18]:
a[3,3]=9
print a
In [19]:
print a[:,:3]
In [20]:
print a[:3,:]
In [21]:
print a[:3,:3]
In [22]:
print a[-3:,-3:]
In [23]:
b=np.array([2,3,5,7,8])
print b
In [24]:
b[::-1]
Out[24]:
In [25]:
a=np.random.randint(0,10,(4,5))
print a
In [26]:
a[::-1]
Out[26]:
In [27]:
print np.fliplr(a)
In [28]:
a.astype(float)
Out[28]:
In [35]:
print np.arange(16)[::2]
In [45]:
(-1,)+(1,2,3)+(4,5)
Out[45]:
In [ ]: