parameters: (obj, itemsize=None, copy=True, unicode=None, order=None)
return_statement: return val.view(chararray)
docstring: Create a `chararray`.
  
      .. note::
         This class is provided for numarray backward-compatibility.
         New code (not concerned with numarray compatibility) should use
         arrays of type `string_` or `unicode_` and use the free functions
         in :mod:`numpy.char <numpy.core.defchararray>` for fast
         vectorized string operations instead.
  
      Versus a regular NumPy array of type `str` or `unicode`, this
      class adds the following functionality:
  
        1) values automatically have whitespace removed from the end
           when indexed
  
        2) comparison operators automatically remove whitespace from the
           end when comparing values
  
        3) vectorized string operations are provided as methods
           (e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``)
  
      Parameters
      ----------
      obj : array of str or unicode-like
  
      itemsize : int, optional
          `itemsize` is the number of characters per scalar in the
          resulting array.  If `itemsize` is None, and `obj` is an
          object array or a Python list, the `itemsize` will be
          automatically determined.  If `itemsize` is provided and `obj`
          is of type str or unicode, then the `obj` string will be
          chunked into `itemsize` pieces.
  
      copy : bool, optional
          If true (default), then the object is copied.  Otherwise, a copy
          will only be made if __array__ returns a copy, if obj is a
          nested sequence, or if a copy is needed to satisfy any of the other
          requirements (`itemsize`, unicode, `order`, etc.).
  
      unicode : bool, optional
          When true, the resulting `chararray` can contain Unicode
          characters, when false only 8-bit characters.  If unicode is
          None and `obj` is one of the following:
  
            - a `chararray`,
            - an ndarray of type `str` or `unicode`
            - a Python str or unicode object,
  
          then the unicode setting of the output array will be
          automatically determined.
  
      order : {'C', 'F', 'A'}, optional
          Specify the order of the array.  If order is 'C' (default), then the
          array will be in C-contiguous order (last-index varies the
          fastest).  If order is 'F', then the returned array
          will be in Fortran-contiguous order (first-index varies the
          fastest).  If order is 'A', then the returned array may
          be in any order (either C-, Fortran-contiguous, or even
          discontiguous).
docstring_summary: Create a `chararray`.
docstring_tokens: Create a chararray .
function: def array(obj, itemsize=None, copy=True, unicode=None, order=None):
      """
      Create a `chararray`.
  
      .. note::
         This class is provided for numarray backward-compatibility.
         New code (not concerned with numarray compatibility) should use
         arrays of type `string_` or `unicode_` and use the free functions
         in :mod:`numpy.char <numpy.core.defchararray>` for fast
         vectorized string operations instead.
  
      Versus a regular NumPy array of type `str` or `unicode`, this
      class adds the following functionality:
  
        1) values automatically have whitespace removed from the end
           when indexed
  
        2) comparison operators automatically remove whitespace from the
           end when comparing values
  
        3) vectorized string operations are provided as methods
           (e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``)
  
      Parameters
      ----------
      obj : array of str or unicode-like
  
      itemsize : int, optional
          `itemsize` is the number of characters per scalar in the
          resulting array.  If `itemsize` is None, and `obj` is an
          object array or a Python list, the `itemsize` will be
          automatically determined.  If `itemsize` is provided and `obj`
          is of type str or unicode, then the `obj` string will be
          chunked into `itemsize` pieces.
  
      copy : bool, optional
          If true (default), then the object is copied.  Otherwise, a copy
          will only be made if __array__ returns a copy, if obj is a
          nested sequence, or if a copy is needed to satisfy any of the other
          requirements (`itemsize`, unicode, `order`, etc.).
  
      unicode : bool, optional
          When true, the resulting `chararray` can contain Unicode
          characters, when false only 8-bit characters.  If unicode is
          None and `obj` is one of the following:
  
            - a `chararray`,
            - an ndarray of type `str` or `unicode`
            - a Python str or unicode object,
  
          then the unicode setting of the output array will be
          automatically determined.
  
      order : {'C', 'F', 'A'}, optional
          Specify the order of the array.  If order is 'C' (default), then the
          array will be in C-contiguous order (last-index varies the
          fastest).  If order is 'F', then the returned array
          will be in Fortran-contiguous order (first-index varies the
          fastest).  If order is 'A', then the returned array may
          be in any order (either C-, Fortran-contiguous, or even
          discontiguous).
      """
      if isinstance(obj, (_bytes, _unicode)):
          if unicode is None:
              if isinstance(obj, _unicode):
                  unicode = True
              else:
                  unicode = False
  
          if itemsize is None:
              itemsize = _len(obj)
          shape = _len(obj) // itemsize
  
          if unicode:
              if sys.maxunicode == 0xffff:
                  # On a narrow Python build, the buffer for Unicode
                  # strings is UCS2, which doesn't match the buffer for
                  # NumPy Unicode types, which is ALWAYS UCS4.
                  # Therefore, we need to convert the buffer.  On Python
                  # 2.6 and later, we can use the utf_32 codec.  Earlier
                  # versions don't have that codec, so we convert to a
                  # numerical array that matches the input buffer, and
                  # then use NumPy to convert it to UCS4.  All of this
                  # should happen in native endianness.
                  obj = obj.encode('utf_32')
              else:
                  obj = _unicode(obj)
          else:
              # Let the default Unicode -> string encoding (if any) take
              # precedence.
              obj = _bytes(obj)
  
          return chararray(shape, itemsize=itemsize, unicode=unicode,
                           buffer=obj, order=order)
  
      if isinstance(obj, (list, tuple)):
          obj = numpy.asarray(obj)
  
      if isinstance(obj, ndarray) and issubclass(obj.dtype.type, character):
          # If we just have a vanilla chararray, create a chararray
          # view around it.
          if not isinstance(obj, chararray):
              obj = obj.view(chararray)
  
          if itemsize is None:
              itemsize = obj.itemsize
              # itemsize is in 8-bit chars, so for Unicode, we need
              # to divide by the size of a single Unicode character,
              # which for NumPy is always 4
              if issubclass(obj.dtype.type, unicode_):
                  itemsize //= 4
  
          if unicode is None:
              if issubclass(obj.dtype.type, unicode_):
                  unicode = True
              else:
                  unicode = False
  
          if unicode:
              dtype = unicode_
          else:
              dtype = string_
  
          if order is not None:
              obj = numpy.asarray(obj, order=order)
          if (copy or
                  (itemsize != obj.itemsize) or
                  (not unicode and isinstance(obj, unicode_)) or
                  (unicode and isinstance(obj, string_))):
              obj = obj.astype((dtype, long(itemsize)))
          return obj
  
      if isinstance(obj, ndarray) and issubclass(obj.dtype.type, object):
          if itemsize is None:
              # Since no itemsize was specified, convert the input array to
              # a list so the ndarray constructor will automatically
              # determine the itemsize for us.
              obj = obj.tolist()
              # Fall through to the default case
  
      if unicode:
          dtype = unicode_
      else:
          dtype = string_
  
      if itemsize is None:
          val = narray(obj, dtype=dtype, order=order, subok=True)
      else:
          val = narray(obj, dtype=(dtype, itemsize), order=order, subok=True)
      return val.view(chararray)
function_tokens: def array ( obj , itemsize = None , copy = True , unicode = None , order = None ) : if isinstance ( obj , ( _bytes , _unicode ) ) : if unicode is None : if isinstance ( obj , _unicode ) : unicode = True else : unicode = False if itemsize is None : itemsize = _len ( obj ) shape = _len ( obj ) // itemsize if unicode : if sys . maxunicode == 0xffff : # On a narrow Python build, the buffer for Unicode # strings is UCS2, which doesn't match the buffer for # NumPy Unicode types, which is ALWAYS UCS4. # Therefore, we need to convert the buffer.  On Python # 2.6 and later, we can use the utf_32 codec.  Earlier # versions don't have that codec, so we convert to a # numerical array that matches the input buffer, and # then use NumPy to convert it to UCS4.  All of this # should happen in native endianness. obj = obj . encode ( 'utf_32' ) else : obj = _unicode ( obj ) else : # Let the default Unicode -> string encoding (if any) take # precedence. obj = _bytes ( obj ) return chararray ( shape , itemsize = itemsize , unicode = unicode , buffer = obj , order = order ) if isinstance ( obj , ( list , tuple ) ) : obj = numpy . asarray ( obj ) if isinstance ( obj , ndarray ) and issubclass ( obj . dtype . type , character ) : # If we just have a vanilla chararray, create a chararray # view around it. if not isinstance ( obj , chararray ) : obj = obj . view ( chararray ) if itemsize is None : itemsize = obj . itemsize # itemsize is in 8-bit chars, so for Unicode, we need # to divide by the size of a single Unicode character, # which for NumPy is always 4 if issubclass ( obj . dtype . type , unicode_ ) : itemsize //= 4 if unicode is None : if issubclass ( obj . dtype . type , unicode_ ) : unicode = True else : unicode = False if unicode : dtype = unicode_ else : dtype = string_ if order is not None : obj = numpy . asarray ( obj , order = order ) if ( copy or ( itemsize != obj . itemsize ) or ( not unicode and isinstance ( obj , unicode_ ) ) or ( unicode and isinstance ( obj , string_ ) ) ) : obj = obj . astype ( ( dtype , long ( itemsize ) ) ) return obj if isinstance ( obj , ndarray ) and issubclass ( obj . dtype . type , object ) : if itemsize is None : # Since no itemsize was specified, convert the input array to # a list so the ndarray constructor will automatically # determine the itemsize for us. obj = obj . tolist ( ) # Fall through to the default case if unicode : dtype = unicode_ else : dtype = string_ if itemsize is None : val = narray ( obj , dtype = dtype , order = order , subok = True ) else : val = narray ( obj , dtype = ( dtype , itemsize ) , order = order , subok = True ) return val . view ( chararray )