nodes: 0, module; 1, function_definition; 2, function_name:view; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, if_statement; 18, if_statement; 19, expression_statement; 20, expression_statement; 21, comment:# allow override of some properties; 22, if_statement; 23, if_statement; 24, if_statement; 25, if_statement; 26, if_statement; 27, return_statement; 28, identifier:shape; 29, None; 30, identifier:chunks; 31, None; 32, identifier:dtype; 33, None; 34, identifier:fill_value; 35, None; 36, identifier:filters; 37, None; 38, identifier:read_only; 39, None; 40, identifier:synchronizer; 41, None; 42, comment:"""Return an array sharing the same data.
  
          Parameters
          ----------
          shape : int or tuple of ints
              Array shape.
          chunks : int or tuple of ints, optional
              Chunk shape.
          dtype : string or dtype, optional
              NumPy dtype.
          fill_value : object
              Default value to use for uninitialized portions of the array.
          filters : sequence, optional
              Sequence of filters to use to encode chunk data prior to
              compression.
          read_only : bool, optional
              True if array should be protected against modification.
          synchronizer : object, optional
              Array synchronizer.
  
          Notes
          -----
          WARNING: This is an experimental feature and should be used with care.
          There are plenty of ways to generate errors and/or cause data
          corruption.
  
          Examples
          --------
  
          Bypass filters:
  
              >>> import zarr
              >>> import numpy as np
              >>> np.random.seed(42)
              >>> labels = ['female', 'male']
              >>> data = np.random.choice(labels, size=10000)
              >>> filters = [zarr.Categorize(labels=labels,
              ...                            dtype=data.dtype,
              ...                            astype='u1')]
              >>> a = zarr.array(data, chunks=1000, filters=filters)
              >>> a[:]
              array(['female', 'male', 'female', ..., 'male', 'male', 'female'],
                    dtype='<U6')
              >>> v = a.view(dtype='u1', filters=[])
              >>> v.is_view
              True
              >>> v[:]
              array([1, 2, 1, ..., 2, 2, 1], dtype=uint8)
  
          Views can be used to modify data:
  
              >>> x = v[:]
              >>> x.sort()
              >>> v[:] = x
              >>> v[:]
              array([1, 1, 1, ..., 2, 2, 2], dtype=uint8)
              >>> a[:]
              array(['female', 'female', 'female', ..., 'male', 'male', 'male'],
                    dtype='<U6')
  
          View as a different dtype with the same item size:
  
              >>> data = np.random.randint(0, 2, size=10000, dtype='u1')
              >>> a = zarr.array(data, chunks=1000)
              >>> a[:]
              array([0, 0, 1, ..., 1, 0, 0], dtype=uint8)
              >>> v = a.view(dtype=bool)
              >>> v[:]
              array([False, False,  True, ...,  True, False, False])
              >>> np.all(a[:].view(dtype=bool) == v[:])
              True
  
          An array can be viewed with a dtype with a different item size, however
          some care is needed to adjust the shape and chunk shape so that chunk
          data is interpreted correctly:
  
              >>> data = np.arange(10000, dtype='u2')
              >>> a = zarr.array(data, chunks=1000)
              >>> a[:10]
              array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint16)
              >>> v = a.view(dtype='u1', shape=20000, chunks=2000)
              >>> v[:10]
              array([0, 0, 1, 0, 2, 0, 3, 0, 4, 0], dtype=uint8)
              >>> np.all(a[:].view('u1') == v[:])
              True
  
          Change fill value for uninitialized chunks:
  
              >>> a = zarr.full(10000, chunks=1000, fill_value=-1, dtype='i1')
              >>> a[:]
              array([-1, -1, -1, ..., -1, -1, -1], dtype=int8)
              >>> v = a.view(fill_value=42)
              >>> v[:]
              array([42, 42, 42, ..., 42, 42, 42], dtype=int8)
  
          Note that resizing or appending to views is not permitted:
  
              >>> a = zarr.empty(10000)
              >>> v = a.view()
              >>> try:
              ...     v.resize(20000)
              ... except PermissionError as e:
              ...     print(e)
              operation not permitted for views
  
          """; 43, assignment; 44, assignment; 45, assignment; 46, comparison_operator:read_only is None; 47, block; 48, comparison_operator:synchronizer is None; 49, block; 50, assignment; 51, assignment; 52, comparison_operator:dtype is None; 53, block; 54, else_clause; 55, comparison_operator:shape is None; 56, block; 57, else_clause; 58, comparison_operator:chunks is not None; 59, block; 60, comparison_operator:fill_value is not None; 61, block; 62, comparison_operator:filters is not None; 63, block; 64, identifier:a; 65, identifier:store; 66, attribute; 67, identifier:chunk_store; 68, attribute; 69, identifier:path; 70, attribute; 71, identifier:read_only; 72, None; 73, expression_statement; 74, identifier:synchronizer; 75, None; 76, expression_statement; 77, identifier:a; 78, call; 79, attribute; 80, True; 81, identifier:dtype; 82, None; 83, expression_statement; 84, block; 85, identifier:shape; 86, None; 87, expression_statement; 88, block; 89, identifier:chunks; 90, None; 91, expression_statement; 92, expression_statement; 93, identifier:fill_value; 94, None; 95, expression_statement; 96, identifier:filters; 97, None; 98, expression_statement; 99, identifier:self; 100, identifier:_store; 101, identifier:self; 102, identifier:_chunk_store; 103, identifier:self; 104, identifier:_path; 105, assignment; 106, assignment; 107, identifier:Array; 108, argument_list; 109, identifier:a; 110, identifier:_is_view; 111, assignment; 112, expression_statement; 113, expression_statement; 114, assignment; 115, expression_statement; 116, expression_statement; 117, assignment; 118, assignment; 119, assignment; 120, assignment; 121, identifier:read_only; 122, attribute; 123, identifier:synchronizer; 124, attribute; 125, keyword_argument; 126, keyword_argument; 127, keyword_argument; 128, keyword_argument; 129, keyword_argument; 130, keyword_argument; 131, identifier:dtype; 132, attribute; 133, assignment; 134, assignment; 135, identifier:shape; 136, attribute; 137, assignment; 138, assignment; 139, identifier:chunks; 140, call; 141, attribute; 142, identifier:chunks; 143, attribute; 144, identifier:fill_value; 145, attribute; 146, identifier:filters; 147, identifier:self; 148, identifier:_read_only; 149, identifier:self; 150, identifier:_synchronizer; 151, identifier:store; 152, identifier:store; 153, identifier:path; 154, identifier:path; 155, identifier:chunk_store; 156, identifier:chunk_store; 157, identifier:read_only; 158, identifier:read_only; 159, identifier:synchronizer; 160, identifier:synchronizer; 161, identifier:cache_metadata; 162, True; 163, identifier:self; 164, identifier:_dtype; 165, identifier:dtype; 166, call; 167, attribute; 168, identifier:dtype; 169, identifier:self; 170, identifier:_shape; 171, identifier:shape; 172, call; 173, attribute; 174, identifier:shape; 175, identifier:normalize_chunks; 176, argument_list; 177, identifier:a; 178, identifier:_chunks; 179, identifier:a; 180, identifier:_fill_value; 181, identifier:a; 182, identifier:_filters; 183, attribute; 184, argument_list; 185, identifier:a; 186, identifier:_dtype; 187, identifier:normalize_shape; 188, argument_list; 189, identifier:a; 190, identifier:_shape; 191, identifier:chunks; 192, identifier:shape; 193, attribute; 194, identifier:np; 195, identifier:dtype; 196, identifier:dtype; 197, identifier:shape; 198, identifier:dtype; 199, identifier:itemsize
code: def view(self, shape=None, chunks=None, dtype=None,
               fill_value=None, filters=None, read_only=None,
               synchronizer=None):
          """Return an array sharing the same data.
  
          Parameters
          ----------
          shape : int or tuple of ints
              Array shape.
          chunks : int or tuple of ints, optional
              Chunk shape.
          dtype : string or dtype, optional
              NumPy dtype.
          fill_value : object
              Default value to use for uninitialized portions of the array.
          filters : sequence, optional
              Sequence of filters to use to encode chunk data prior to
              compression.
          read_only : bool, optional
              True if array should be protected against modification.
          synchronizer : object, optional
              Array synchronizer.
  
          Notes
          -----
          WARNING: This is an experimental feature and should be used with care.
          There are plenty of ways to generate errors and/or cause data
          corruption.
  
          Examples
          --------
  
          Bypass filters:
  
              >>> import zarr
              >>> import numpy as np
              >>> np.random.seed(42)
              >>> labels = ['female', 'male']
              >>> data = np.random.choice(labels, size=10000)
              >>> filters = [zarr.Categorize(labels=labels,
              ...                            dtype=data.dtype,
              ...                            astype='u1')]
              >>> a = zarr.array(data, chunks=1000, filters=filters)
              >>> a[:]
              array(['female', 'male', 'female', ..., 'male', 'male', 'female'],
                    dtype='<U6')
              >>> v = a.view(dtype='u1', filters=[])
              >>> v.is_view
              True
              >>> v[:]
              array([1, 2, 1, ..., 2, 2, 1], dtype=uint8)
  
          Views can be used to modify data:
  
              >>> x = v[:]
              >>> x.sort()
              >>> v[:] = x
              >>> v[:]
              array([1, 1, 1, ..., 2, 2, 2], dtype=uint8)
              >>> a[:]
              array(['female', 'female', 'female', ..., 'male', 'male', 'male'],
                    dtype='<U6')
  
          View as a different dtype with the same item size:
  
              >>> data = np.random.randint(0, 2, size=10000, dtype='u1')
              >>> a = zarr.array(data, chunks=1000)
              >>> a[:]
              array([0, 0, 1, ..., 1, 0, 0], dtype=uint8)
              >>> v = a.view(dtype=bool)
              >>> v[:]
              array([False, False,  True, ...,  True, False, False])
              >>> np.all(a[:].view(dtype=bool) == v[:])
              True
  
          An array can be viewed with a dtype with a different item size, however
          some care is needed to adjust the shape and chunk shape so that chunk
          data is interpreted correctly:
  
              >>> data = np.arange(10000, dtype='u2')
              >>> a = zarr.array(data, chunks=1000)
              >>> a[:10]
              array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint16)
              >>> v = a.view(dtype='u1', shape=20000, chunks=2000)
              >>> v[:10]
              array([0, 0, 1, 0, 2, 0, 3, 0, 4, 0], dtype=uint8)
              >>> np.all(a[:].view('u1') == v[:])
              True
  
          Change fill value for uninitialized chunks:
  
              >>> a = zarr.full(10000, chunks=1000, fill_value=-1, dtype='i1')
              >>> a[:]
              array([-1, -1, -1, ..., -1, -1, -1], dtype=int8)
              >>> v = a.view(fill_value=42)
              >>> v[:]
              array([42, 42, 42, ..., 42, 42, 42], dtype=int8)
  
          Note that resizing or appending to views is not permitted:
  
              >>> a = zarr.empty(10000)
              >>> v = a.view()
              >>> try:
              ...     v.resize(20000)
              ... except PermissionError as e:
              ...     print(e)
              operation not permitted for views
  
          """
  
          store = self._store
          chunk_store = self._chunk_store
          path = self._path
          if read_only is None:
              read_only = self._read_only
          if synchronizer is None:
              synchronizer = self._synchronizer
          a = Array(store=store, path=path, chunk_store=chunk_store, read_only=read_only,
                    synchronizer=synchronizer, cache_metadata=True)
          a._is_view = True
  
          # allow override of some properties
          if dtype is None:
              dtype = self._dtype
          else:
              dtype = np.dtype(dtype)
              a._dtype = dtype
          if shape is None:
              shape = self._shape
          else:
              shape = normalize_shape(shape)
              a._shape = shape
          if chunks is not None:
              chunks = normalize_chunks(chunks, shape, dtype.itemsize)
              a._chunks = chunks
          if fill_value is not None:
              a._fill_value = fill_value
          if filters is not None:
              a._filters = filters
  
          return a