In [1]:
from __future__ import print_function, unicode_literals
from arraybuffer import arraybuffer, arraybuffer_descr
import numpy as np
In [2]:
# create arraybuffer description
a_dsc = arraybuffer_descr((3,4), 'd', 'C')
# create arraybuffer from description
a = arraybuffer(a_dsc, zero=1)
print(a_dsc.shape, repr(a_dsc.format), repr(a_dsc.order), a_dsc.itemsize)
(3, 4) b'd' b'C' 8
In [5]:
na = np.array(a, copy=False)
nb = np.array(a, copy=False)
nc = np.array(a, copy=True)

na.fill(0)
na[0,:] = 1

print(na)
print(nb)
print(nc)
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
In [6]:
na.shape = (4,3)
print(na)
print(nb)
[[ 1.  1.  1.]
 [ 1.  0.  0.]
 [ 0.  0.  0.]
 [ 0.  0.  0.]]
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
In [7]:
nd = np.array(a, copy=True)
nd[0,:]=2
print(nd)
print(na)
print(nb)
print(nc)
[[ 2.  2.  2.  2.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
[[ 1.  1.  1.]
 [ 1.  0.  0.]
 [ 0.  0.  0.]
 [ 0.  0.  0.]]
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
[[ 1.  1.  1.  1.]
 [ 0.  0.  0.  0.]
 [ 0.  0.  0.  0.]]
In [ ]:
 
In [ ]: