Escolar Documentos
Profissional Documentos
Cultura Documentos
Description
Create a 3*3 array using list_1 = [1,2,3] list_2 = [4,5,6] list_3 = [7,8,9]
Execution time limit
5 seconds
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0]
list_2 = input_list[1]
list_3 = input_list[2]
import numpy as np
array_1 = np.array([list_1,list_2,list_3])
print(array_1)
Status
Passed
Execution time
0.48s
CPU
0s
Memory
23MB
Description
Testcase passed! The solution's output matches the expected output.
Input
[[1,2,3],[4,5,6],[7,8,9]]
Solution output
[[1 2 3]
[4 5 6]
[7 8 9]]
Expected output
[[1 2 3]
[4 5 6]
[7 8 9]]
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0]
list_2 = input_list[1]
import numpy as np
array_1 = np.array(list_1)
array_2 = np.array(list_2)
array_3 = array_1*array_2
print(list(array_3))
heck
Status
Passed
Execution time
0.53s
CPU
0s
Memory
22MB
Description
Testcase passed! The solution's output matches the expected output.
Input
[[2,3,4,5],[7,8,9,6]]
Solution output
Expected output
import ast,sys
input_str = sys.stdin.read()
input_tuple = ast.literal_eval(input_str)
list_1 = input_tuple[0]
tuple_1 = input_tuple[1]
import numpy as np
array_1 = np.array(list_1)
array_2 = np.array(tuple_1)
print(array_1)
print(array_2)
Description
Create an array of all ones of size 3*3 having integer values.
Hint: Use dtype to specify integer
import numpy as np
array_ones = np.ones((3,3),dtype=int)
print(array_ones)
Status
Passed
Execution time
0.51s
CPU
0s
Memory
22MB
Description
Testcase passed! The solution's output matches the expected output.
Solution output
[[1 1 1]
[1 1 1]
[1 1 1]]
Expected output
[[1 1 1]
[1 1 1]
[1 1 1]]
Description
Create an array of first 10 multiples of 5 using the 'arange' function.
import numpy as np
array_multipleof5 =np.arange(5,55,5)
print(array_multipleof5)
2D Array
Description
Create an array using list list_1 = [10,11,12,13] and list_2 = [15,12,13,14] and
print the shape and dimension of the array created.
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0]
list_2 = input_list[1]
import numpy as np
array_1 = np.array([list_1,list_2])
print(array_1.shape)
print(array_1.ndim)
Status
Passed
Execution time
0.47s
CPU
0s
Memory
21MB
Description
Testcase passed! The solution's output matches the expected output.
Input
[[10,11,12,13],[15,12,13,14]]
Solution output
(2, 4)
2
Expected output
(2, 4)
2
2D Array
Description
From a 2D array extract all the rows of the 2 column.
Hint: 2 column will have index value as 1.
Execution time limit
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
import numpy as np
array_2d =np.array(input_list)
print(array_2d[:,1])
All sample testcases passed! (1/1)
Testcase #1
Status
Passed
Execution time
0.51s
CPU
0s
Memory
22MB
Description
Testcase passed! The solution's output matches the expected output.
Input
[[5,6,7],[7,6,5],[0,8,7]]
Solution output
[6 6 8]
Expected output
[6 6 8]
You'll often work with extremely large datasets, and thus it is important to point
for you to understand how much computation time (and memory) you can save using
NumPy, compared to standard python lists.
Let's compare the computation times of arrays and lists for a simple task of
calculating the element-wise product of numbers.
In this case, NumPy is an order of magnitude faster than lists. This is with arrays
of size in millions, but you may work on much larger arrays of sizes in order of
billions. Then, the difference is even larger.
array_3 = np.hstack((array_1,array_2))
print(array_3)
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0:2]
list_2 = input_list[2:4]
import numpy as np
array_1 = np.array(list_1)
array_2 = np.array(list_2)
array_3 =np.hstack((array_1,array_2))
print(function(array_3))
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0]
list_2 = input_list[1]
list_3 = input_list[2]
import numpy as np
array_1 = np.array([list_1,list_2,list_3])
eigen =np.linalg.eig(array_1)
inv = np.linalg.inv(array_1)
det = np.linalg.det(array_1)
print(eigen)
print(inv)
print(det)
Create a series using list = [6,7,8,9,2,3,4,5] and print the output series as the
square of each number in the list.
Hint: If input series = 1,2,3 the output series should be 1,4,25
Hint: First create the series and then using apply and lambda find the output
series.
import numpy as np
import pandas as pd
series_1 = pd.Series([6,7, 8, 9, 2,3,4,5])
series_2 = series_1**2
print(series_1)
print(series_2)
Given a dataframe 'd1' use the following commands and analyse the result.
describe()
columns
shape
import numpy as np
import pandas as pd
df = pd.read_csv('https://query.data.world/s/vBDCsoHCytUSLKkLvq851k2b8JOCkF')
print(df.describe())
print(df.columns)
print(df.shape)
Sorting Dataframes
Description
Sort the dataframe on 'month' and 'day' in ascending order in the dataframe 'df'.
import pandas as pd
df = pd.read_csv('https://query.data.world/s/vBDCsoHCytUSLKkLvq851k2b8JOCkF')
df_2 =df.sort_values(by=['month', 'day'], ascending = True)
print(df_2.head(20))