<jupyter_start><jupyter_text><jupyter_code># Question 1:
# Create a numpy array starting from 2 till 50 with a stepsize of 3. 
import numpy as np
arr = np.arange(2, 50, 3)
print(arr)
# Questions 2: 
# Accept two lists of 5 elements each from the user.  
# Convert them to numpy arrays. Concatenate these arrays and print it. Also sort these arrays and print it. 
import numpy as np
# Accept two lists of 5 elements each from the user.
lst1 = [] 
n = int(input("Enter number of elements : ")) 
for i in range(0, n): 
    ele = input()
    lst1.append(ele) 
print(lst1)

lst2 = [] 
n = int(input("Enter number of elements : ")) 
for i in range(0, n): 
    ele = input()
    lst2.append(ele) 
print(lst2)
# Convert them to numpy arrays.
npArray1 = np.array([lst1])
print('Contents of the ndArray : ')
print(npArray1)
print("\n")
npArray2 = np.array([lst2])
print('Contents of the ndArray : ')
print(npArray2)
# Concatenate these arrays and print it.
arr = np.concatenate((npArray1,npArray2))
print("Concatenate array : ",arr)

# sort these arrays and print it.
arr2 = np.sort(arr)         
print ("Sorted array : ",arr2) 
# Questions 3:  
# Write a code snippet to find the dimensions of a ndarray and its size. 
arr = np.array( [[ 1, 2, 3],
                 [ 4, 2, 5]] )
 

print("Array is of type: ", type(arr))
 

print("No. of dimensions: ", arr.ndim)
 
 
print("Size of array: ", arr.size)
 

# Questions 4:  
# How to convert a 1D array into a 2D array? Demonstrate with the help of a code snippet 
# Hint: np.newaxis, np.expand_dims 
# Call numpy.reshape(a, newshape) with a as a 1D array 
# and newshape as the tuple (-1, x) to reshape the array to a 2D array containing nested arrays of x values each.
arr_1D = np.array([1,2,3,4,5,6,7,8,9])
print("1D Array is : ",arr_1D)

# 2D Array
arr_2D = np.reshape(arr_1D, (-1, 3))
print("2D Array is : ",arr_2D)

# Questions 5: 
# Consider two square numpy arrays. Stack them vertically and horizontally. 
# Hint: Use vstack(), hstack() 
a = np.array([[5,10], 
              [20,25]]) 
  
b = np.array([[35,40], 
              [50,55]]) 
  
# vertical stacking 
print("Vertical stacking:\n", np.vstack((a, b))) 
  
# horizontal stacking 
print("\nHorizontal stacking:\n", np.hstack((a, b))) 
  
# Questions 6: 
# How to get unique items and counts of unique items? 
# Using given syntax = numpy.unique(arr, return_counts=False)
# We sorted unique elements of an array with their corresponding frequency counts NumPy array.
import numpy as np
arr = np.array([10, 20, 5, 10, 8, 20, 8, 9]) 
  
unique, count = np.unique(arr, return_counts = True) 
# unique items 
print("Unique items:", unique) 
  
# counts of unique items 
print("counts of unique items:", count)<jupyter_output>Unique items: [ 5  8  9 10 20]
counts of unique items: [1 2 1 2 2]
{'fraction_non_alphanumeric': 0.12688172043010754, 'fraction_numerical': 0.036917562724014336, 'mean_word_length': 3.5016129032258063, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '172597', 'license': 'Apache-2.0', 'n_tokens_mistral': 1047, 'n_tokens_neox': 962, 'n_words': 362, 'path': '_Data_Science_Batch_1_Assignment_3.ipynb', 'repo_name': 'snehalshinde16/Letsupgrade-Data-Scienc-Essential-Batch-01', 'size': '2790'}