Skip to content

Alternative solutions for Exercises N36, N81 #214

@Artur-Arstamyan

Description

@Artur-Arstamyan

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)]))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions