<jupyter_start><jupyter_text>Numpy - Numerical Python<jupyter_code># convert list to numpy array

import numpy as np

a = [8,6,2,4,7,3]
a = np.asarray(a)

print(a)
type(a)
# convert set to numpy array

import numpy as np

a = {2,8,6,3,8,9,10}
a = np.asarray(a)

print(a)
type(a)
# creating numpy array

x = np.array([10,20,53,6,52,51,7,5,2])

print(x)
print(x[2])
x[2] = 26 # replace a value
print(x)
type(x)
# get multiple row and column

y = np.array([[1,2,3,4],[5,6,7,8]])
print(y)
type(y)
# shape of the array

y = np.array([[1,2,3],[5,6,7]])
print(y.shape)
# create a null matrix

null = np.zeros((2,5))
print(null)
print(null.shape)
# identity matrix

identity = np.eye(4,4)
print(identity)
# array of all elements as 1

one = np.ones((2,3))
print(one)
# array with an constant element

constant = np.full((3,4),8)
print(constant)
print(constant.shape)
# create an array with random elements

random_array = np.random.random((2,3))
print(random_array)
integer_random = np.random.randint(1,5,(3,3))  # random integer between 1 - 5
print(integer_random)
type(integer_random)
# transpose array

array = np.random.randint(1,10,(2,3))
print(array)

transposed_array = array.T
print(transposed_array)
# reshaping array

array = np.random.random((3,4))
print(array)

reshaped_array = array.reshape(12,1)
print(reshaped_array)<jupyter_output>[[0.9336723  0.33735373 0.6341308  0.68719586]
 [0.26344779 0.04575413 0.81062975 0.03302233]
 [0.76554746 0.55855585 0.12496545 0.41773592]]
[[0.9336723 ]
 [0.33735373]
 [0.6341308 ]
 [0.68719586]
 [0.26344779]
 [0.04575413]
 [0.81062975]
 [0.03302233]
 [0.76554746]
 [0.55855585]
 [0.12496545]
 [0.41773592]]<jupyter_text>Numpy array slicingSlicing -> taking elements from one index to another index<jupyter_code>import numpy as np

array = np.array([8,5,4,9,6,3])
print(array[1:5])  # [start:end]
print(array)
print(array[:4])
print(array)
print(array[2:])
print(array)
print(array[1:5:2])  # [start:end:step]
print(array[::3])  # 3 step from 0 index<jupyter_output>[8 5 4 9 6 3]
[5 9]
[8 9]<jupyter_text>Slicing in 2D array<jupyter_code>a = np.array([[2,4,8,6,5,2],[8,7,2,6,9,4]])
print(a)
print(a[1,1:4])  # slicing rows
print(a[:,1:3])  # slicing column<jupyter_output>[[4 8]
 [7 2]]
{'fraction_non_alphanumeric': 0.17810677433826827, 'fraction_numerical': 0.14984297891431134, 'mean_word_length': 5.5588235294117645, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '91666', 'license': 'MIT', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1010, 'n_words': 204, 'path': 'Data Science/Numpy and Pandas/Numpy_Basics.ipynb', 'repo_name': 'sandeeprawat28/Data-Science', 'size': '2229'}