Numpy arrays | Sololearn: Learn to code for FREE!

0

Numpy arrays

Let A & B are two numpy arrays. A is of shape (5, ) and B is of shape (5,1). What is the difference between these two? How can I reshape B to shape of A ?

5/26/2020 6:38:02 AM

Peter Parker

2 Answers

New Answer

+4

Peter Parker import numpy as np a=[1,2,3,4,5] d=np.array(a) print(np.shape(d)) Output: (5,) __________________________________ b=[[1],[2],[3],[4],[5]] e=np.array(b) print(np.shape(e)) Output : (5,1) ____________________________________ Now how to reshape b to a : print(e.reshape(5,)) output :[1,2,3,4,5] --------------------------------------------------------- By above examples, (5,) means array shaped with 1 row and 5 columns : (5,1) means array shaped with 5 rows and 1 column : I hope it helped,Happy Coding 🤗

0