<jupyter_start><jupyter_text>Reshape  Shape: The shape of an array is the number of elements in each dimension.<jupyter_code>import numpy as np
arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
arr.shape
arr
arr = np.array([[[1,2,3,4],[4,5,6,5]],[[3,4,5,8],[5,6,7,9]],[[23,34,56,78],[45,67,78,56]]])
arr
arr.shape
arr = np.array([1, 2, 3, 4], ndmin=5)

arr.shape<jupyter_output><empty_output><jupyter_text>Reshape: Changing the shape of array- By reshaping we can add or remove dimensions or change number of elements in each dimension.<jupyter_code>a = np.array([1,2,3,4,5,6,7,8,9,67,12,45,24,678,89,56,454,23,56,76,89,89,65,45])
a.shape
a.ndim
a<jupyter_output><empty_output><jupyter_text>Reshape from 1-D to 2-D<jupyter_code>a2d = a.reshape(6,4)
a2d
a2d.shape
a2d.ndim<jupyter_output><empty_output><jupyter_text>Reshape into 3-D 3 d array reshape((a,b,c)) = a is number of batches, b is number of rows, c is number of columns<jupyter_code>a3da = a.reshape(4,3,2)
a3da
a3da.shape
a3da.ndim
a3db = a2d.reshape(4,3,2)
a3db<jupyter_output><empty_output><jupyter_text>4 D<jupyter_code>a.reshape(2,2,3,2)<jupyter_output><empty_output><jupyter_text>High dimensions<jupyter_code>a.reshape(1,2,2,3,2)<jupyter_output><empty_output><jupyter_text>Can we reshape into any shape?<jupyter_code>a.reshape(7,3)<jupyter_output><empty_output><jupyter_text>Unknown dimension:- You are allowed to have one "unknown" dimension.- Meaning that you do not have to specify an exact number for one of the dimensions in the reshape method.- Pass -1 as the value, and NumPy will calculate this number for you.<jupyter_code>a
a.shape
a.reshape(1,24)
a.reshape(1,-1)
a.reshape(-1,1)
a.reshape(3,-1)
a.reshape(5,-1)
a.reshape(-1,2,3)
a.reshape(2,-1,4)
a.reshape(2,-1,4)
a.reshape(-1,2,2,2) # 3 3d matrices of 2 2*2 2d matrices<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16136114160263446, 'fraction_numerical': 0.08342480790340286, 'mean_word_length': 6.960698689956332, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '347246', 'license': 'MIT', 'n_tokens_mistral': 867, 'n_tokens_neox': 809, 'n_words': 168, 'path': 'Day 10.ipynb', 'repo_name': 'jaiyesh/15Petro-Numpy-Days', 'size': '1822'}