本文整理汇总了Python中tensorflow.python.ops.manip_ops.roll函数的典型用法代码示例。如果您正苦于以下问题:Python roll函数的具体用法?Python roll怎么用?Python roll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了roll函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testRollAxisMustBeScalarOrVectorRaises
def testRollAxisMustBeScalarOrVectorRaises(self):
tensor = [[1, 2], [3, 4]]
shift = 1
axis = [[0, 1]]
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"axis must be a scalar or a 1-D vector"):
manip_ops.roll(tensor, shift, axis).eval()
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:manip_ops_test.py
示例2: testRollAxisOutOfRangeRaises
def testRollAxisOutOfRangeRaises(self):
tensor = [1, 2]
shift = 1
axis = 1
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"is out of range"):
manip_ops.roll(tensor, shift, axis).eval()
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:manip_ops_test.py
示例3: testRollInputMustVectorHigherRaises
def testRollInputMustVectorHigherRaises(self):
tensor = 7
shift = 1
axis = 0
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"input must be 1-D or higher"):
manip_ops.roll(tensor, shift, axis).eval()
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:manip_ops_test.py
示例4: testRollShiftAndAxisMustBeSameSizeRaises
def testRollShiftAndAxisMustBeSameSizeRaises(self):
tensor = [[1, 2], [3, 4]]
shift = [1]
axis = [0, 1]
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"shift and axis must have the same size"):
manip_ops.roll(tensor, shift, axis).eval()
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:8,代码来源:manip_ops_test.py
示例5: testNegativeAxis
def testNegativeAxis(self):
self._testAll(np.random.randint(-100, 100, (5)).astype(np.int32), 3, -1)
self._testAll(np.random.randint(-100, 100, (4, 4)).astype(np.int32), 3, -2)
# Make sure negative axis should be 0 <= axis + dims < dims
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"is out of range"):
manip_ops.roll(np.random.randint(-100, 100, (4, 4)).astype(np.int32),
3, -10).eval()
开发者ID:AnishShah,项目名称:tensorflow,代码行数:9,代码来源:manip_ops_test.py
示例6: testRollShiftMustBeScalarOrVectorRaises
def testRollShiftMustBeScalarOrVectorRaises(self):
# The shift should be a scalar or 1-D, checked in kernel.
tensor = [[1, 2], [3, 4]]
shift = array_ops.placeholder(dtype=dtypes.int32)
axis = 1
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"shift must be a scalar or a 1-D vector"):
manip_ops.roll(tensor, shift, axis).eval(feed_dict={shift: [[0, 1]]})
开发者ID:AnishShah,项目名称:tensorflow,代码行数:9,代码来源:manip_ops_test.py
示例7: testRollShiftAndAxisMustBeSameSizeRaises
def testRollShiftAndAxisMustBeSameSizeRaises(self):
# The shift and axis must be same size, checked in kernel.
tensor = [[1, 2], [3, 4]]
shift = array_ops.placeholder(dtype=dtypes.int32)
axis = [0, 1]
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"shift and axis must have the same size"):
manip_ops.roll(tensor, shift, axis).eval(feed_dict={shift: [1]})
开发者ID:AnishShah,项目名称:tensorflow,代码行数:9,代码来源:manip_ops_test.py
示例8: testRollInputMustVectorHigherRaises
def testRollInputMustVectorHigherRaises(self):
# The input should be 1-D or higher, checked in kernel.
tensor = array_ops.placeholder(dtype=dtypes.int32)
shift = 1
axis = 0
with self.test_session():
with self.assertRaisesRegexp(errors_impl.InvalidArgumentError,
"input must be 1-D or higher"):
manip_ops.roll(tensor, shift, axis).eval(feed_dict={tensor: 7})
开发者ID:AnishShah,项目名称:tensorflow,代码行数:9,代码来源:manip_ops_test.py
示例9: _testGradient
def _testGradient(self, np_input, shift, axis):
with self.test_session():
inx = constant_op.constant(np_input.tolist())
xs = list(np_input.shape)
y = manip_ops.roll(inx, shift, axis)
# Expected y's shape to be the same
ys = xs
jacob_t, jacob_n = gradient_checker.compute_gradient(
inx, xs, y, ys, x_init_value=np_input)
self.assertAllClose(jacob_t, jacob_n, rtol=1e-5, atol=1e-5)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:10,代码来源:manip_ops_test.py
示例10: _testRoll
def _testRoll(self, np_input, shift, axis):
expected_roll = np.roll(np_input, shift, axis)
with self.test_session():
roll = manip_ops.roll(np_input, shift, axis)
self.assertAllEqual(roll.eval(), expected_roll)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:5,代码来源:manip_ops_test.py
示例11: testInvalidShiftAndAxisNotEqualShape
def testInvalidShiftAndAxisNotEqualShape(self):
# The shift and axis must be same size, checked in shape function.
with self.assertRaisesRegexp(ValueError, "both shapes must be equal"):
manip_ops.roll([[1, 2], [3, 4]], [1], [0, 1])
开发者ID:AnishShah,项目名称:tensorflow,代码行数:4,代码来源:manip_ops_test.py
示例12: testInvalidShiftShape
def testInvalidShiftShape(self):
# The shift should be a scalar or 1-D, checked in shape function.
with self.assertRaisesRegexp(
ValueError, "Shape must be at most rank 1 but is rank 2"):
manip_ops.roll([[1, 2], [3, 4]], [[0, 1]], 1)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:5,代码来源:manip_ops_test.py
示例13: testInvalidInputShape
def testInvalidInputShape(self):
# The input should be 1-D or higher, checked in shape function.
with self.assertRaisesRegexp(
ValueError, "Shape must be at least rank 1 but is rank 0"):
manip_ops.roll(7, 1, 0)
开发者ID:AnishShah,项目名称:tensorflow,代码行数:5,代码来源:manip_ops_test.py
示例14: _RollGrad
def _RollGrad(op, grad):
# The gradient is just the roll reversed
shift = op.inputs[1]
axis = op.inputs[2]
roll_grad = manip_ops.roll(grad, -shift, axis)
return roll_grad, None, None
开发者ID:ChengYuXiang,项目名称:tensorflow,代码行数:6,代码来源:manip_grad.py
注:本文中的tensorflow.python.ops.manip_ops.roll函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论