Numpy.append — NumPy V1.23 Manual

Skip to main content Back to top Ctrl+K
  • User Guide
  • API reference
  • Building from source
  • Development
  • Release notes
  • Learn
  • NEPs
Choose version
  • GitHub

Section Navigation

  • NumPy’s module structure
  • Array objects
  • Universal functions (ufunc)
  • Routines and objects by topic
    • Constants
    • Array creation routines
    • Array manipulation routines
      • numpy.copyto
      • numpy.ndim
      • numpy.shape
      • numpy.size
      • numpy.reshape
      • numpy.ravel
      • numpy.ndarray.flat
      • numpy.ndarray.flatten
      • numpy.moveaxis
      • numpy.rollaxis
      • numpy.swapaxes
      • numpy.ndarray.T
      • numpy.transpose
      • numpy.permute_dims
      • numpy.matrix_transpose
      • numpy.atleast_1d
      • numpy.atleast_2d
      • numpy.atleast_3d
      • numpy.broadcast
      • numpy.broadcast_to
      • numpy.broadcast_arrays
      • numpy.expand_dims
      • numpy.squeeze
      • numpy.asarray
      • numpy.asanyarray
      • numpy.asmatrix
      • numpy.asfortranarray
      • numpy.ascontiguousarray
      • numpy.asarray_chkfinite
      • numpy.require
      • numpy.concatenate
      • numpy.concat
      • numpy.stack
      • numpy.block
      • numpy.vstack
      • numpy.hstack
      • numpy.dstack
      • numpy.column_stack
      • numpy.split
      • numpy.array_split
      • numpy.dsplit
      • numpy.hsplit
      • numpy.vsplit
      • numpy.unstack
      • numpy.tile
      • numpy.repeat
      • numpy.delete
      • numpy.insert
      • numpy.append
      • numpy.resize
      • numpy.trim_zeros
      • numpy.unique
      • numpy.pad
      • numpy.flip
      • numpy.fliplr
      • numpy.flipud
      • numpy.roll
      • numpy.rot90
    • Bit-wise operations
    • String functionality
    • Datetime support functions
    • Data type routines
    • Mathematical functions with automatic domain
    • Floating point error handling
    • Exceptions and Warnings
    • Discrete Fourier Transform
    • Functional programming
    • Input and output
    • Indexing routines
    • Linear algebra
    • Logic functions
    • Masked array operations
    • Mathematical functions
    • Miscellaneous routines
    • Polynomials
    • Random sampling
    • Set routines
    • Sorting, searching, and counting
    • Statistics
    • Test support
    • Window functions
  • Typing (numpy.typing)
  • Packaging
  • NumPy C-API
  • Array API standard compatibility
  • CPU/SIMD optimizations
  • Thread Safety
  • Global Configuration Options
  • NumPy security
  • Testing guidelines
  • Status of numpy.distutils and migration advice
  • numpy.distutils user guide
  • NumPy and SWIG
  • NumPy reference
  • Routines and objects by topic
  • Array manipulation routines
  • numpy.append
numpy.append# numpy.append(arr, values, axis=None)[source]#

Append values to the end of an array.

Parameters: arrarray_like

Values are appended to a copy of this array.

valuesarray_like

These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use.

axisint, optional

The axis along which values are appended. If axis is not given, both arr and values are flattened before use.

Returns: appendndarray

A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is None, out is a flattened array.

See also

insert

Insert elements into an array.

delete

Delete elements from an array.

Examples

Try it in your browser! >>> importnumpyasnp >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])

When axis is specified, values must have the correct shape.

>>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0) Traceback (most recent call last): ... ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s) >>> a = np.array([1, 2], dtype=int) >>> c = np.append(a, []) >>> c array([1., 2.]) >>> c.dtype float64

Default dtype for empty ndarrays is float64 thus making the output of dtype float64 when appended with dtype int64

Go BackOpen In Tab On this page
  • append

Tag » Add Element In Numpy Array Python