Ejemplo n.º 1
0
#!/usr/bin/python
import arrayfire as af

af.print_array(af.constant(100, 3,3, dtype=af.f32))
af.print_array(af.constant(25, 3,3, dtype=af.c32))
af.print_array(af.constant(2**50, 3,3, dtype=af.s64))
af.print_array(af.constant(2+3j, 3,3))
af.print_array(af.constant(3+5j, 3,3, dtype=af.c32))

af.print_array(af.range(3, 3))
af.print_array(af.iota(3, 3, tile_dims=(2,2)))

af.print_array(af.randu(3, 3, 1, 2))
af.print_array(af.randu(3, 3, 1, 2, af.b8))
af.print_array(af.randu(3, 3, dtype=af.c32))

af.print_array(af.randn(3, 3, 1, 2))
af.print_array(af.randn(3, 3, dtype=af.c32))

af.set_seed(1024)
assert(af.get_seed() == 1024)

af.print_array(af.identity(3, 3, 1, 2, af.b8))
af.print_array(af.identity(3, 3, dtype=af.c32))

a = af.randu(3, 4)
b = af.diag(a, extract=True)
c = af.diag(a, 1, extract=True)

af.print_array(a)
af.print_array(b)
Ejemplo n.º 2
0
#!/usr/bin/python
import arrayfire as af
import array as host

a = af.array([1, 2, 3])
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())


a = af.array(host.array('d', [4, 5, 6]))
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

a = af.array(host.array('l', [7, 8, 9] * 4), (2, 5))
af.print_array(a)
print(a.elements(), a.type(), a.dims(), a.numdims())
print(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
print(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
print(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())
#!/usr/bin/python
import arrayfire as af

a = af.randu(5, 5)
b = af.randu(5, 5)
w = af.randu(5, 1)

af.print_array(af.mean(a, dim=0))
af.print_array(af.mean(a, weights=w, dim=0))
print(af.mean(a))
print(af.mean(a, weights=w))

af.print_array(af.var(a, dim=0))
af.print_array(af.var(a, isbiased=True, dim=0))
af.print_array(af.var(a, weights=w, dim=0))
print(af.var(a))
print(af.var(a, isbiased=True))
print(af.var(a, weights=w))

af.print_array(af.stdev(a, dim=0))
print(af.stdev(a))

af.print_array(af.var(a, dim=0))
af.print_array(af.var(a, isbiased=True, dim=0))
print(af.var(a))
print(af.var(a, isbiased=True))

af.print_array(af.median(a, dim=0))
print(af.median(w))

print(af.corrcoef(a, b))
#!/usr/bin/python
import arrayfire as af

a = af.randu(3, 3)

print(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a))

af.print_array(af.sum(a, 0))
af.print_array(af.sum(a, 1))

af.print_array(af.product(a, 0))
af.print_array(af.product(a, 1))

af.print_array(af.min(a, 0))
af.print_array(af.min(a, 1))

af.print_array(af.max(a, 0))
af.print_array(af.max(a, 1))

af.print_array(af.count(a, 0))
af.print_array(af.count(a, 1))

af.print_array(af.any_true(a, 0))
af.print_array(af.any_true(a, 1))

af.print_array(af.all_true(a, 0))
af.print_array(af.all_true(a, 1))

af.print_array(af.accum(a, 0))
af.print_array(af.accum(a, 1))