Numpy array have functions for matrices ,linear algebra ,Fourier Transform. Numpy arrays provide 50x more speed than a python list.
Numpy array have functions for matrices ,linear algebra ,Fourier Transform. Numpy arrays provide 50x more speed than a python list.
pip install numpy
pip install numpy
import numpy
import numpy as np
import numpy as np
pi = np.float32(3.16)
print(type(pi))
print(pi)
<class 'numpy.float32'>
3.16
num_arr = np.array(42)
print(type(num_arr))
print(num_arr)
num_arr = np.array([1, 2, 3, 4, 5])
print(num_arr)
print(type(num_arr))
print(num_arr.shape)
print(num_arr.ndim)
[1 2 3 4 5]
<class 'numpy.ndarray'>
(5,)
1
num_arr1=np.array([1, 2, 3, 4, 5])
num_arr2=np.array([6, 7, 8, 9, 10])
TwoD = np.array( [ num_arr1 , num_arr2 ] )
print(TwoD)
print(TwoD.shape)
print(TwoD.ndim)
[[ 1 2 3 4 5]
[ 6 7 8 9 10]]
(2, 5)
2
num_arr1=np.array([1, 2, 3])
num_arr2=np.array([4, 5, 6])
num_arr3=np.array([7, 8, 9])
T3D=np.array([
[num_arr1,num_arr2],
[num_arr2,num_arr3],
[num_arr1,num_arr3]
]
)
print(T3D)
print(T3D.shape)
print(T3D.ndim)
[[[1 2 3]
[4 5 6]]
[[4 5 6]
[7 8 9]]
[[1 2 3]
[7 8 9]]]
(3, 2, 3)
3
Furthermore, we will use ndim attribute to determine the number of dimensions.
np.array([[[[1,2,3], [4,5,6], [7,8,9]], [[10,11,12], [13,14,15], [16,17,18]]], [[[19,20,21], [22,23,24], [25,26,27]], [[28,29,30], [31,32,33], [34,35,36]]]])
print(a.ndim)
a
4
array([[[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
[[10, 11, 12],
[13, 14, 15],
[16, 17, 18]]],
[[[19, 20, 21],
[22, 23, 24],
[25, 26, 27]],
[[28, 29, 30],
[31, 32, 33],
[34, 35, 36]]]])
Attribute shape determines the length of each dimension inside the whole array since we know the 4 dimensions are created in the array.
import numpy as np
e = np.array([[[[4, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]]])
e.shape
(2, 2, 3, 3)
By using concatenate, we can combine two arrays along a given axis. In the following examples, we will be showcasing two examples where axis value is set to 0 by default, and we have to set any other value manually.
import numpy as np
arr1 = np.array([1.1, 2.1, 3.1])
arr2 = np.array([1.2, 2.2, 3.2])
arr = np.concatenate((arr1, arr2))
arr
array([1.1, 2.1, 3.1, 1.2, 2.2, 3.2])
import numpy as np
arr1 = np.array([[1.1, 2.1, 3.1],[1.2, 2.2, 3.2],[1.3, 2.3, 3.3]])
arr2 = np.array([[1,2,3]])
arr = np.concatenate((arr1, arr2.T),axis=1)
arr
array([[1.1, 2.1, 3.1, 1. ],
[1.2, 2.2, 3.2, 2. ],
[1.3, 2.3, 3.3, 3. ]])
The Numpy stack allows us to join multiple arrays. And we can also use an axis with this method similar to concatenate.
import numpy as np
arr1 = np.array([1, 2, 3,4])
arr2 = np.array([4, 5, 6,7])
arr3 = np.array([7, 8, 9,10])
arr4 = np.array([10, 11, 12,13])
arr4 = np.array([11, 12, 13,14])
arr = np.stack((arr1, arr2 , arr3 , arr4 ),axis=0)
print(arr)
[[ 1 2 3 4]
[ 4 5 6 7]
[ 7 8 9 10]
[11 12 13 14]]
import numpy as np
arr1 = np.array([1, 2, 3,4])
arr2 = np.array([4, 5, 6,7])
arr3 = np.array([7, 8, 9,10])
arr4 = np.array([10, 11, 12,13])
arr4 = np.array([11, 12, 13,14])
arr = np.stack((arr1, arr2 , arr3 , arr4 ),axis=1)
print(arr)
[[ 1 4 7 11]
[ 2 5 8 12]
[ 3 6 9 13]
[ 4 7 10 14]]
import numpy as np
arr1 = np.array([1, 2, 3,4])
arr2 = np.array([4, 5, 6,7])
arr3 = np.array([7, 8, 9,10])
arr4 = np.array([10, 11, 12,13])
arr4 = np.array([11, 12, 13,14])
arr = np.stack((arr1, arr2 , arr3 , arr4 ),axis=-1)
print(arr)
[[ 1 4 7 11]
[ 2 5 8 12]
[ 3 6 9 13]
[ 4 7 10 14]]
Also, take note of axis 1 and axis-1 output
Depth stack combines multiple arrays depth-wise
import numpy as np
arr1 = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
arr2 = np.array([[4, 5, 6],[4, 5, 6],[4, 5, 6]])
arr = np.dstack(( arr1 , arr2 ))
print(arr)
[[[1 4]
[2 5]
[3 6]]
[[1 4]
[2 5]
[3 6]]
[[1 4]
[2 5]
[3 6]]]
Horizontal stack combines arrays in a horizontal direction along columns. This can be similar to concatenate.
import numpy as np
arr1 = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
arr2 = np.array([[4, 5, 6],[4, 5, 6],[4, 5, 6]])
arr = np.hstack(( arr1 , arr2 ))
print(arr)
[[1 2 3 4 5 6]
[1 2 3 4 5 6]
[1 2 3 4 5 6]]
Horizontal stack combines arrays in a horizontal direction along columns. And it is obviously similar to axis 0.
import numpy as np
arr1 = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
arr2 = np.array([[4, 5, 6],[4, 5, 6],[4, 5, 6]])
arr = np.vstack(( arr1 , arr2 ))
print(arr)
[[1 2 3]
[1 2 3]
[1 2 3]
[4 5 6]
[4 5 6]
[4 5 6]]
Horizontal stack combines arrays in a horizontal direction along columns. And it is obviously similar to axis 0.
import numpy as np
arr1 = np.array([[1, 2, 3],[1, 2, 3],[1, 2, 3]])
arr2 = np.array([[4, 5, 6],[4, 5, 6],[4, 5, 6]])
arr = np.vstack(( arr1 , arr2 ))
print(arr)
[[1 2 3]
[1 2 3]
[1 2 3]
[4 5 6]
[4 5 6]
[4 5 6]]
This can be a super guide for you to start and excel in your data science career.
ANCOVA is an extension of ANOVA (Analysis of Variance) that combines blocks of regression analysis and ANOVA. Which makes it Analysis of Covariance.
What if we learn topics in a desirable way!! What if we learn to write Python codes from gamers data !!
Start using NotebookLM today and embark on a smarter, more efficient learning journey!
This article will walk you through the different data types of numbers.
TF-IDF method belongs to domain of information retrieval,
Python has several types of operators. Mathematical, Assignment, Comparison, Logical, Identity, Membership, Bitwise operators.
If a software language is easy in terms of declaring variables, then consider that half of the time and efforts are saved. Python is one of the easiest and convenient languages for declaring variables.”
If a software language is easy in terms of declaring variables, then consider that half of the time and effort are saved. Python is one of the easiest and most convenient languages for declaring variables.
Chatbots are a necessity of the current IT era. Chatbots offer visitors round-the-clock customer service.
Improve your analytical skills by practicing the following tasks
Improve your analytical skills by practicing the following tasks