Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Python for Data Science/Numpy Questions.ipynb
3074 views
Kernel: Python 3 (ipykernel)

Write a NumPy program to test whether none of the elements of a given array is zero.

Write a NumPy program to create an array of 5 zeros, 5 ones, 5 fives.

Write a NumPy program to generate an array of 15 random numbers from a standard normal distribution

## Use seed to fix random generated values import numpy as np np.random.seed(0) x=np.random.rand(2,2) #np.random.rand(2,2) x
array([[0.5488135 , 0.71518937], [0.60276338, 0.54488318]])

For following Array

  • A=[[1,2,3],[5,6,7],[13,14,-8]

  • B =[[[1,1,1],[2,3,4]],[[2,5,7],[3,8,7]]] Find:

      1. Mean of second row(A) and mean of first row from first axis(B)

      1. Reshape array B and save it to a variable C

      1. Do matrix multiplication of array C and a unity matrix(create shape according to the mul properties)

      1. create a subset for row 3 of matrix A and save it in variable d.

Write a NumPy program to create a vector with values ranging from 10 to 40 and print all values except the first and last.

Write a NumPy program to create a vector with values from 1 to 15 and change the sign of the numbers in the range from 10 to 15.

Write a NumPy program to create a 3x4 matrix filled with values from 10 to 21

Write a NumPy program to compute the inner product of two given vectors

Write a NumPy program to create a structured array from given student name, height, class and their data types. Now sort the array on height.

import numpy as np data_type = [('name', 'S15'), ('class', int), ('height', float)] students_details = [('James', 5, 48.5), ('Nail', 6, 52.5),('Paul', 5, 42.10), ('Pit', 5, 40.11)] # create a structured array students = np.array(students_details, dtype=data_type) print("Original array:") print(students) print("Sort by height") print(np.sort(students, order='height'))

Write a NumPy program to add, subtract, multiply, divide arguments element-wise.

Write a NumPy program to get the minimum and maximum value of a given array along the second axis.

Write a NumPy program to display all the dates for the month of May, 2021

import numpy as np print("May, 2021") print(np.arange('2021-05', '2021-06', dtype='datetime64[D]'))
May, 2021 ['2021-05-01' '2021-05-02' '2021-05-03' '2021-05-04' '2021-05-05' '2021-05-06' '2021-05-07' '2021-05-08' '2021-05-09' '2021-05-10' '2021-05-11' '2021-05-12' '2021-05-13' '2021-05-14' '2021-05-15' '2021-05-16' '2021-05-17' '2021-05-18' '2021-05-19' '2021-05-20' '2021-05-21' '2021-05-22' '2021-05-23' '2021-05-24' '2021-05-25' '2021-05-26' '2021-05-27' '2021-05-28' '2021-05-29' '2021-05-30' '2021-05-31']

Write a NumPy program to capitalize the first letter, lowercase, uppercase, swapcase, title-case of all the elements of a given array

import numpy as np x = np.array(['ml', 'PYTHON', 'Data Science', 'Numpy'], dtype=np.str) print("Original Array:") print(x) capitalized_case = np.char.capitalize(x) lowered_case = np.char.lower(x) uppered_case = np.char.upper(x) swapcased_case = np.char.swapcase(x) titlecased_case = np.char.title(x) print("\nCapitalized: ", capitalized_case) print("Lowered: ", lowered_case) print("Uppered: ", uppered_case) print("Swapcased: ", swapcased_case) print("Titlecased: ", titlecased_case)