Theano和numpy一样,支持基本的下标取值方法和高级的下标取值方法。

因为theano中没有boolean类型,所以不支持boolean类型的masks。

# head file support
import numpy as np

numpy中的 Advanced Indexing:

高级下标取值用于获取非元组序列对象中的元素时,一般为 bdarray结构。

通常可以使用的取值方法包括:integer 和boolean

  • integer indexing
>>> x = np.array([[1, 2], [3, 4], [5, 6]])
>>> x[[0, 1, 2], [0, 1, 0]]
array([1, 4, 5])
  • boolean indexing
>>> x = np.array([1., -1., -2., 3])
>>> x[x < 0] += 20
>>> x
array([  1.,  19.,  18.,   3.])

numpy 的mask运算:

>>> n = np.arange(9).reshape(3,3)
>>> n[n > 4]  # mask
array([5, 6, 7, 8])

theano中mask运算:

>>> t = theano.tensor.arange(9).reshape((3,3))
>>> t[t > 4].eval()  # an array with shape (3, 3, 3)
array([[[0, 1, 2],
        [0, 1, 2],
        [0, 1, 2]],

       [[0, 1, 2],
        [0, 1, 2],
        [3, 4, 5]],

       [[3, 4, 5],
        [3, 4, 5],
        [3, 4, 5]]], dtype=int8)

相关文章:

  • 2022-12-23
  • 2021-10-01
  • 2021-11-02
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-08-01
猜你喜欢
  • 2022-01-06
  • 2022-01-01
  • 2021-06-11
  • 2021-06-07
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案