## Indexing with a zero-dimensional Boolean array import pyOcean_cpu as ocean a = ocean.asTensor(True,ocean.bool); b = ocean.zeros([3,3]) b[a] = 3 print(b)
import pyOcean_cpu as ocean a = ocean.zeros([3, 4], ocean.float) print(a) a.dealloc() print(a) print(a.storage)
print("## Index binding") idx = ocean.index[[1, 2, 3]] idx.bind([5], True) failTest("idx.bind([5,7],True)") failTest("idx.bind([6],True)") idx.bind([5], [8], True) failTest("idx.bind([5],[4],True)") idx = ocean.index[1, 3] idx.bind([5, 5], True) failTest("idx.bind([5,6,7])") print("\n## Scalar") idx = ocean.index[10] failTest("idx.bind([5],True)") idx = ocean.index[1, 2, 3] failTest("idx.bind([5,5,2],True)") print("\n## Indices") idx = ocean.index[1, [1, 2, 10]] failTest("idx.bind([5,5])") print("\n## Mask") idx = ocean.index[ocean.zeros([5, 6], ocean.bool)] failTest("idx.bind([5,5])") print("\n## Ellipsis") idx = ocean.index[1, ..., 3, ..., 5] failTest("idx.bind([5,5,5])")
import pyOcean_cpu as ocean a = ocean.zeros([3,4,5]) a[1,2,3] = 4 a[-1,-1,-1] = 99 print(a)
import pyOcean_cpu as ocean a = ocean.zeros([0, 5], ocean.float) b = ocean.ones([5], ocean.float) c = a * b print(c)
import pyOcean_cpu as ocean a = ocean.zeros([5, 0], ocean.float) b = ocean.ones([0, 5], ocean.float) c = a * b print(c)
import pyOcean_cpu as ocean a = ocean.zeros([5,5]) a[1,...,3] = 99 print(a)
## Set index with byteswapped data import pyOcean_cpu as ocean import sys def exceptionMsg(): print("Expected error: %s" % str(sys.exc_info()[1])) # Tensor is byteswapped A = ocean.zeros([4, 5]) A.byteswap() A[2:4, 1:3] = 3 print(A) B = ocean.arange(2 * 2).reshape(2, 2) + 1 print(B) A.fill(0) A[1:3, 2:4] = B print(A) B.byteswap() A.fill(0) A[2:0:-1, 3:1:-1] = B print(A) A = ocean.zeros([4, 5]) A[[0, 3], [3, 0]] = B print(A)
import pyOcean_cpu as ocean a = ocean.zeros([3, 4]) print(a) a = ocean.zeros([3, 4], ocean.int8) print(a) a = ocean.zeros([3, 4], ocean.cpu) print(a) a = ocean.zeros([3, 4], ocean.float, ocean.cpu) print(a)