Alternative solutions for Exercises N36, N81
Author: Artur-ArstamyanCreated Sep 25, 2024Updated Oct 21, 2024
Exercise N36 - Extract the integer part of a random array of positive numbers using 4 different methods
np.modf() returns two arrays: one with the fractional part and one with the integer part.
import numpy as np
Z = np.random.uniform(0,10,10)
print(np.modf(Z)[1])Exercise N81 - Consider an array Z = [1,2,3,4,5,6,7,8,9,10,11,12,13,14], how to generate an array R = [[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]? Using np.roll function
import numpy as np
Z = [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
print(np.array([np.roll(Z, -i)[:4] for i in range(len(Z)-3)]))Source: rougier/numpy-100