mirror of
https://github.com/apachecn/ailearning.git
synced 2026-04-24 10:34:08 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -6,13 +6,13 @@
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
import theano
|
||||
import theano.tensor as T
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Using gpu device 1: Tesla C2075 (CNMeM is disabled)
|
||||
|
||||
```
|
||||
@@ -23,7 +23,7 @@ Using gpu device 1: Tesla C2075 (CNMeM is disabled)
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
x = T.fmatrix()
|
||||
|
||||
print type(x)
|
||||
@@ -31,7 +31,7 @@ print type(T.fmatrix)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
<class 'theano.tensor.var.TensorVariable'>
|
||||
<class 'theano.tensor.type.TensorType'>
|
||||
|
||||
@@ -43,7 +43,7 @@ print type(T.fmatrix)
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
x = T.scalar('myvar', dtype='int32')
|
||||
x = T.iscalar('myvar')
|
||||
x = T.TensorType(dtype='int32', broadcastable=())('myvar')
|
||||
@@ -93,7 +93,7 @@ x = T.TensorType(dtype='int32', broadcastable=())('myvar')
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
dtensor5 = T.TensorType('float64', (False,)*5)
|
||||
|
||||
x = dtensor5()
|
||||
@@ -108,12 +108,12 @@ x = dtensor5()
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
print x.ndim
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
5
|
||||
|
||||
```
|
||||
@@ -124,12 +124,12 @@ print x.ndim
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
print x.type
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
TensorType(float64, 5D)
|
||||
|
||||
```
|
||||
@@ -140,12 +140,12 @@ TensorType(float64, 5D)
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
print x.dtype
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
float64
|
||||
|
||||
```
|
||||
@@ -156,7 +156,7 @@ float64
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
shape = T.ivector("shape")
|
||||
|
||||
y = x.reshape(shape, ndim=3)
|
||||
@@ -167,12 +167,12 @@ y = x.reshape(shape, ndim=3)
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
print x.ndim, y.ndim
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
5 3
|
||||
|
||||
```
|
||||
@@ -197,7 +197,7 @@ print x.ndim, y.ndim
|
||||
|
||||
In [10]:
|
||||
|
||||
```
|
||||
```py
|
||||
z = y.dimshuffle(("x", 1, 2, 0))
|
||||
|
||||
print z
|
||||
@@ -205,7 +205,7 @@ print z.ndim
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
DimShuffle{x,1,2,0}.0
|
||||
4
|
||||
|
||||
@@ -217,14 +217,14 @@ DimShuffle{x,1,2,0}.0
|
||||
|
||||
In [11]:
|
||||
|
||||
```
|
||||
```py
|
||||
z = x.flatten(ndim=2)
|
||||
|
||||
print z.ndim
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2
|
||||
|
||||
```
|
||||
@@ -241,12 +241,12 @@ print z.ndim
|
||||
|
||||
In [12]:
|
||||
|
||||
```
|
||||
```py
|
||||
print filter(lambda t: t.isalpha(), dir(x))
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
['T', 'all', 'any', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', 'argmax', 'argmin', 'argsort', 'astype', 'broadcastable', 'ceil', 'choose', 'clip', 'clone', 'compress', 'conj', 'conjugate', 'copy', 'cos', 'cosh', 'cumprod', 'cumsum', 'diagonal', 'dimshuffle', 'dot', 'dtype', 'eval', 'exp', 'fill', 'flatten', 'floor', 'imag', 'index', 'log', 'max', 'mean', 'min', 'name', 'ndim', 'nonzero', 'norm', 'owner', 'prod', 'ptp', 'ravel', 'real', 'repeat', 'reshape', 'round', 'shape', 'sin', 'sinh', 'size', 'sort', 'sqrt', 'squeeze', 'std', 'sum', 'swapaxes', 'tag', 'take', 'tan', 'tanh', 'trace', 'transpose', 'trunc', 'type', 'var']
|
||||
|
||||
```
|
||||
@@ -261,12 +261,12 @@ print filter(lambda t: t.isalpha(), dir(x))
|
||||
|
||||
In [13]:
|
||||
|
||||
```
|
||||
```py
|
||||
print T.shape(x)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Shape.0
|
||||
|
||||
```
|
||||
@@ -277,7 +277,7 @@ Shape.0
|
||||
|
||||
In [14]:
|
||||
|
||||
```
|
||||
```py
|
||||
x = T.tensor3()
|
||||
|
||||
print T.shape_padleft(x)
|
||||
@@ -285,7 +285,7 @@ print T.shape_padright(x)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
DimShuffle{x,0,1,2}.0
|
||||
DimShuffle{0,1,2,x}.0
|
||||
|
||||
@@ -297,14 +297,14 @@ DimShuffle{0,1,2,x}.0
|
||||
|
||||
In [15]:
|
||||
|
||||
```
|
||||
```py
|
||||
print T.shape_padaxis(x, 1)
|
||||
print T.shape_padaxis(x, 0)
|
||||
print T.shape_padaxis(x, -1)
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
DimShuffle{0,x,1,2}.0
|
||||
DimShuffle{x,0,1,2}.0
|
||||
DimShuffle{0,1,2,x}.0
|
||||
|
||||
Reference in New Issue
Block a user