본문 바로가기

Computer Science/[20-4] Numpy 연습6

[Numpy] (6) Array Mathematics HackerRank 문제: https://www.hackerrank.com/challenges/np-array-mathematics/problem Array Mathematics | HackerRank Perform basic mathematical operations on arrays in NumPy. www.hackerrank.com import numpy N,M=map(int,input().split()) A=numpy.array([list(map(int,input().split())) for n in range(N)]) B=numpy.array([list(map(int,input().split())) for n in range(N)]) print(numpy.add(A,B)) print(numpy... 2020. 4. 3.
[Numpy] (5) Eye and Identity HackerRank 문제: https://www.hackerrank.com/challenges/np-eye-and-identity/problem Eye and Identity | HackerRank Create an array using the identity or eye tools from the NumPy module. www.hackerrank.com import numpy as np num = tuple(map(int, input().split(' '))) arr = np.eye(*num, k=0) np.set_printoptions(legacy='1.13') print(arr) 2020. 4. 2.
[Numpy] (4) Zeros and Ones HackerRank 문제: https://www.hackerrank.com/challenges/np-zeros-and-ones/problem Zeros and Ones | HackerRank Print an array using the zeros and ones tools in the NumPy module. www.hackerrank.com import numpy as np num = tuple(map(int, input().split(' '))) print(np.zeros(num, dtype=int)) print(np.ones(num, dtype=int)) 2020. 4. 1.
[Numpy] (3) Concatenate로 여러개의 배열 합치기 HackerRank 문제: https://www.hackerrank.com/challenges/np-concatenate/problem Concatenate | HackerRank Use the concatenate function on 2 arrays. www.hackerrank.com import numpy as np first = input().split(' ') rows1, rows2= int(first[0]), int(first[1]) data1 = [] for _ in range(rows1): next = input().split(' ') data1.append([int(x) for x in next]) data1 = np.array(data1) data2 = [] for _ in range(.. 2020. 3. 31.
[Numpy] (2) Transpose and Flatten, flatten()과 ravel()의 차이점 HackerRank 문제: https://www.hackerrank.com/challenges/np-transpose-and-flatten/problem Transpose and Flatten | HackerRank Use the transpose and flatten tools in the NumPy module to manipulate an array. www.hackerrank.com input: 2 2 1 2 3 4 output: [[1 3] [2 4]] [1 2 3 4] import numpy as np first = input().split(' ') rows, columns = int(first[0]), int(first[1]) data = [] for _ in range(rows): next.. 2020. 3. 30.
[Numpy] (1) Numpy arrays basic HackerRank 문제: https://www.hackerrank.com/challenges/np-arrays/problem Arrays | HackerRank Convert a list to an array using the NumPy package. www.hackerrank.com Input 1 2 3 4 -8 -10 Output [-10. -8. 4. 3. 2. 1.] import numpy def arrays(arr): # 배열의 요소를 모두 float arr = numpy.array(arr, float) # reverse the array arr = numpy.flip(arr) return arr arr = input().strip().split(' ') result = arrays(arr).. 2020. 3. 29.