Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Array Concatenation | Commonly used NumPy Functions
Ultimate NumPy

Array ConcatenationArray Concatenation

Array concatenation is a fundamental operation in NumPy that allows combining arrays along a specified axis to create larger, more comprehensive datasets. Essentially, concatenation involves joining arrays together to form a new array.

NumPy has a concatenate() function that enables you to concatenate arrays along a specified axis:

  • axis=0 (the default value) concatenates the arrays by rows;
  • axis=1 concatenates the arrays by columns.

The first parameter of this function is the sequence of arrays (a tuple or list of arrays) to concatenate, while axis is the second parameter.

Here is an example with 1D arrays:

As you can see, with 1D arrays, everything is quite simple. Concatenation creates a 1D array with the elements of the first array followed by the elements of the second array.

Now let’s concatenate 2D arrays:

Here is the visualization:

Concatenation of 2D arrays

The purple elements correspond to array1, and the green ones to array2.

In fact, we can concatenate any number of arrays, and it will work the same way.

Завдання

Your task is to concatenate the sales data for both products by columns:

  1. Use the correct function for concatenation.
  2. Use sales_data_2021 and sales_data_2022 in this order for concatenation.
  3. Specify the second keyword argument correctly to concatenate by columns.

Все було зрозуміло?

Секція 3. Розділ 6
toggle bottom row
course content

Зміст курсу

Ultimate NumPy

Array ConcatenationArray Concatenation

Array concatenation is a fundamental operation in NumPy that allows combining arrays along a specified axis to create larger, more comprehensive datasets. Essentially, concatenation involves joining arrays together to form a new array.

NumPy has a concatenate() function that enables you to concatenate arrays along a specified axis:

  • axis=0 (the default value) concatenates the arrays by rows;
  • axis=1 concatenates the arrays by columns.

The first parameter of this function is the sequence of arrays (a tuple or list of arrays) to concatenate, while axis is the second parameter.

Here is an example with 1D arrays:

As you can see, with 1D arrays, everything is quite simple. Concatenation creates a 1D array with the elements of the first array followed by the elements of the second array.

Now let’s concatenate 2D arrays:

Here is the visualization:

Concatenation of 2D arrays

The purple elements correspond to array1, and the green ones to array2.

In fact, we can concatenate any number of arrays, and it will work the same way.

Завдання

Your task is to concatenate the sales data for both products by columns:

  1. Use the correct function for concatenation.
  2. Use sales_data_2021 and sales_data_2022 in this order for concatenation.
  3. Specify the second keyword argument correctly to concatenate by columns.

Все було зрозуміло?

Секція 3. Розділ 6
toggle bottom row
some-alt