-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataScience_2.py
42 lines (32 loc) · 990 Bytes
/
DataScience_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 15 16:35:24 2021
author: Sagheb Kohpayeh Araghi
Data Science - Reshape
Task
Given a list of numbers and the number of rows (r), reshape the list into a
2-dimensional array. Note that r divides the length of the list evenly.
Input Format
First line: an integer (r) indicating the number of rows of the 2-dimensional
array
Next line: numbers separated by the space
Output Format
An numpy 2d array of values rounded to the second decimal.
Sample Input
2
1.2 0 0.5 -1
Sample Output
[[ 1.2 0. ]
[ 0.5 -1. ]]
Explanation
The required number of the rows is 2, and we are given a list of 4 numbers;
as
a result the 2d array should be 2 x 2. So the first row is the first two
number and the second row contains the next two numbers in given list.
"""
import numpy as np
r = int(input())
lst = [float(x) for x in input().split()]
arr = np.array(lst)
p= int(len(arr)/r)
print(arr.reshape(r, p))