The input arrays should often be the same data typeĪnother point that I’ll make is that the input arrays should probably contain data of the same data type.īut keep in mind that the data types probably should be the same, but they don’t have to be. If you’re a little confused about this, I suggest that you review Python sequences. Tuples and lists are both types of Python sequences. What’s important to understand is that you need to provide the input arrays to the concatenate function within some type of Python sequence. Alternatively, you could enclose them inside of brackets (i.e., ), which would pass them to concatenate as a Python list.Įither method is acceptable: you can provide the input arrays in a list or a tuple. Because they are enclosed in parenthesis, they are essentially being passed to the concatenate function as a Python tuple. Notice that the arrays – arr1 and arr2 in the above example – are enclosed inside of parenthesis. The input arrays should be provided in a Python sequence There are a few important points that you should know about the input arrays for np.concatenate. When you use the np.concatenate function, you need to provide at least two input arrays. Let’s take a look at each of these separately. a sequence of input arrays (the arrays that you will concatenate together).There are a few parameters and arguments of the np.concatenate function: The parameters and arguments of numpy concatenate Moving forward, this tutorial will assume that you’ve imported NumPy by executing the code import numpy as np. Either case assumes that you’ve imported the NumPy package with the code import numpy as np or import numpy, respectively. In Python code, the concatenate function is typically written as np.concatenate(), although you might also see it written as ncatenate(). Syntactically, there are a few main parts of the function: the name of the function, and several parameters inside of the function that we can manipulate. The syntax of NumPy concatenate is fairly straightforward, particularly if you’re familiar with other NumPy functions. Later in the examples section, I’ll show you how to use concatenate both ways.īefore we discuss concrete examples though, let’s quickly look at the syntax of the np.concatenate function. You can concatenate arrays together vertically (like in the image above), or you can concatenate arrays together horizontally. Second, the concatenate function can operate both vertically and horizontally. There are a couple of things to keep in mind.įirst, NumPy concatenate isn’t exactly like a traditional database join. NumPy concatenate essentially combines together multiple NumPy arrays. We use NumPy to “wrangle” numeric data in Python. NumPy (if you’re not familiar), is a data manipulation package in the Python programming language. The NumPy concatenate function is function from the NumPy package. NumPy concatenate joins together numpy arrays Examples of how to use NumPy concatenateįirst, I’ll start by explaining what the concatenate function does.What the NumPy concatenate function does.If you don’t want to read the full tutorial, click on the appropriate link and it will send you to the relevant section of this tutorial. This tutorial will explain how to use the NumPy concatenate function in Python (which is sometimes called np.concatenate).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |