<jupyter_start><jupyter_text>Combining Arrays<jupyter_code>#import numpy as np

# create array with vstack
from numpy import array
from numpy import vstack,hstack
# create first array
a1 = array([1,2,3])
#print(a1)
# create second array
a2 = array([4,5,6,7])
#print(a2)
# vertical stack
print(a1)
print(a2)

a3=vstack((a1,a2))
print(a3)
print(a3.shape)<jupyter_output><empty_output><jupyter_text>Horizontal Stack<jupyter_code># create array with hstack
from numpy import array
from numpy import hstack
# create first array
a1 = array([1,2,3])
#print(a1)
# create second array
a2 = array([4,5,6,5,6,7,7])
#print(a2)
# create horizontal stack
a3 = hstack((a1, a2))
print(a3)
print(a3.shape)
print(a3.dtype)
a1 = array([[1,2,3],[4,5,6]])
a2 = array([[11,22,33],[44,55,66]])
a1.shape
a2.shape
hstack((a1,a2))
vstack((a1,a2))
a1 = array([1,2,3])
a2 = array([[4,5,6,7],[7,8,9],[10,11,22]])
vstack((a1,a2))
a1[2]<jupyter_output><empty_output><jupyter_text>Index, Slice and Reshape NumPyArrays 1. From List to Arrays2. Array Indexing3. Array Slicing4. Array Reshaping<jupyter_code>#From List to Arrays
#One-Dimensional List to Array
#Two-Dimensional List of Lists to Array<jupyter_output><empty_output><jupyter_text>One-Dimensional List to Array<jupyter_code># create one-dimensional array
from numpy import array
# list of data
data = [11, 22, 33, 44, 55]
# array of data
data = array(data)
print(data)
print(type(data))
data.dtype
print(data.shape)
data.dtype<jupyter_output><empty_output><jupyter_text>one-Dimensional List of Lists to nd-Array<jupyter_code># create two-dimensional array
from numpy import array
# list of data
data = [[11, 22],[33, 44],[55, 66],[77,88]]
# array of data
print(data)
data = array(data)
print(data)
print(type(data))
print(data.shape)

print(data[:2,:1])<jupyter_output>[[11, 22], [33, 44], [55, 66], [77, 88]]
[[11 22]
 [33 44]
 [55 66]
 [77 88]]
<class 'numpy.ndarray'>
(4, 2)
[[11]
 [33]]<jupyter_text>Array Indexing  One-Dimensional Indexing<jupyter_code># index a one-dimensional array
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
# index data
print(data[0])
print(data[4])
# index array out of bounds
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
# index data
print(data[4])
# negative array indexing
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
# index data
print(data[-1])
print(data[-5])<jupyter_output>55
11<jupyter_text>Two-Dimensional Indexing<jupyter_code># index two-dimensional array
from numpy import array
# define array
data = array([
[11, 22],
[33, 44],
[55, 66]])
# index data
print(data[2,1])
# index row of two-dimensional array
from numpy import array
# define array
data = array([
[11, 22],
[33, 44],
[55, 66]])
# index data
print(data[1,1])<jupyter_output>44<jupyter_text>Array Slicing  One-Dimensional Slicing<jupyter_code># slice a one-dimensional array
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
print(data[:])
# slice a subset of a one-dimensional array
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
print(data[0:1])
# negative slicing of a one-dimensional array
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
print(data[-2:])<jupyter_output>[44 55]<jupyter_text>Two-Dimensional Slicing<jupyter_code># split input and output data
from numpy import array
# define array
data = array([
[11, 22, 33],
[44, 55, 66],
[77, 88, 99]])
# separate data
X, y = data[:, :-1], data[:, -1]
print(X)
print(y)
print(y.shape)
print(X.shape)<jupyter_output>[[11 22]
 [44 55]
 [77 88]]
[33 66 99]
(3,)
(3, 2)<jupyter_text>Split Train and Test Rows<jupyter_code># split train and test data
from numpy import array
# define array
data = array([
[11, 22, 33],
[44, 55, 66],
[77, 88, 99]])
# separate data
split = 2
train,test = data[:2,:],data[split:,:]
print(train)
print(test)<jupyter_output>[[11 22 33]
 [44 55 66]]
[[77 88 99]]<jupyter_text>Array Reshaping  Data Shape<jupyter_code># shape of one-dimensional array
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
print(data.shape)
# shape of one-dimensional array
data.shape[1]
# shape of a two-dimensional array
from numpy import array
# list of data
data = [[11, 22],
[33, 44],
[55, 66]]
# array of data
data = array(data)
print(data)
data.shape[0]
data.shape[1]
data.shape[2]
# row and column shape of two-dimensional array
from numpy import array
# list of data
data = [[11, 22],[33, 44],[55, 66]]
# array of data
data = array(data)
print( ' Rows:  ' , data.shape[0])
print( ' Cols:  ', data.shape[1])
data.shape<jupyter_output>Rows:   3
 Cols:   2<jupyter_text>Reshape 1D to 2D Array<jupyter_code># reshape 1D array to 2D
from numpy import array
# define array
data = array([11, 22, 33, 44, 55])
print(data.shape)
print(data)
# reshape
data1 = data.reshape((data.shape[0],1))
print(data1.shape)
print(data1)
data = array([11, 22, 33, 44, 55])
print(data)
print(data.shape)
data1=data.reshape(data.shape[0],1)
print(data1)
data1.shape
data2=data1.reshape((data1.shape[0],data1.shape[1],1))
print(data2)
data2.shape<jupyter_output><empty_output><jupyter_text>Reshape 2D to 3D Array<jupyter_code># reshape 2D array to 3D
from numpy import array
# list of data
data = [[11, 22],[33, 44],[55, 66]]
print(data)
# array of data
data = array(data)
print(data)
print(data.shape)
# reshape
data = data.reshape((data.shape[0], data.shape[1],1))
print(data.shape)
print(data)<jupyter_output>[[11, 22], [33, 44], [55, 66]]
[[11 22]
 [33 44]
 [55 66]]
(3, 2)
(3, 2, 1)
[[[11]
  [22]]

 [[33]
  [44]]

 [[55]
  [66]]]
{'fraction_non_alphanumeric': 0.1630901287553648, 'fraction_numerical': 0.08690987124463519, 'mean_word_length': 5.829059829059829, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '523258', 'license': 'MIT', 'n_tokens_mistral': 2525, 'n_tokens_neox': 2224, 'n_words': 632, 'path': 'Day14-Day15/JuputerNotebook/Numpy.ipynb', 'repo_name': 'amitsagargowda/AIML-Training-Content', 'size': '5592'}