Split Function in NumPy | Python NumPy Tutorial | Python Programming Certification Training | Uplatz

preview_player
Показать описание

In NumPy, the split() function is used to split an array into multiple sub-arrays along a specified axis. It allows you to divide a larger array into smaller segments, creating a list of sub-arrays based on the split points defined by the function.

The syntax of the split() function is as follows:

Parameters:
• array: The input array to be split.
• indices_or_sections: This parameter specifies how to split the array. It can take one of the following values:
• An integer: If indices_or_sections is an integer k, the array will be divided into k equal-sized sub-arrays along the specified axis.
• A 1-D array of indices: If indices_or_sections is a 1-D array, the array will be split at the indices specified in the array along the specified axis.
• axis: This parameter specifies the axis along which the array will be split. The default value is 0, which means the array will be split along the first axis (rows).
The split() function returns a list of sub-arrays.

Examples of using the split() function in NumPy:

import numpy as np

# Creating a one-dimensional array

# Splitting the array into 5 equal-sized sub-arrays
print(sub_arrays)
# Output: [array([1, 2]), array([3, 4]), array([5, 6]), array([7, 8]), array([ 9, 10])]

# Creating a two-dimensional array

# Splitting the array along the rows
print(sub_arrays_rows)
# Output: [array([[1, 2, 3],[4, 5, 6]]), array([[7, 8, 9],[10, 11, 12]])]

# Splitting the array along the columns
print(sub_arrays_cols)
# Output: [array([[1],[4],[7],[10]]), array([[2],[5],[8],[11]]), array([[3],[6],[9],[12]])]

Note that the array must be split into equal-sized sub-arrays when using split() with an integer value for indices_or_sections. Otherwise, you will encounter a ValueError. If you need more flexible splitting, you can use the array_split() function or the split() method of the array, which allow for uneven splits.

#NumPy#ArraySplitting#PythonDataScience#DataProcessing#NumPySplit#ArrayManipulation#PythonArrays#DataScience#MachineLearning#DataAnalysis

---------------------------------------------------------------------------------------------------------------

Welcome to Uplatz!
Uplatz is a leading organization providing Management Consulting, IT Training, Virtual employees, and Analytics services.

Uplatz is well known for providing instructor-led training and video-based courses on SAP, Oracle, Salesforce, Cloud Computing, AWS, Microsoft Azure, Big Data, Machine Learning, Python, R, SQL, Google Cloud Platform, Microsoft, IBM, Cisco, Adobe Technologies, DevOps, Project Management, Digital Marketing.

For any questions, queries, or payment related issues, simply contact us at -

-----------------------------------------------------------------------------------------------------------
Рекомендации по теме
visit shbcf.ru