We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Numpy
- Shape and Reshape
- Discussions
Shape and Reshape
Shape and Reshape
Sort by
recency
|
380 Discussions
|
Please Login in order to post a comment
import numpy user_input = input().split() user_input = numpy.array(user_input,dtype = 'int') print(numpy.reshape(user_input,(3,3)))
Check this out :)
import numpy
inp=list(map(int,input().split())) change_array=numpy.array(inp) change_array.shape=(3,3) print(change_array)
Explanation: * input() -> takes in the input * .split() -> turns the input into a list of strings. ie. ["1", "2", "3", etc] * map(int, ...) -> turns the list of strings into integers * np.array(a1) -> Turns the list into a numpy array * np.reshape(a1, (3,3)) -> makes the array to be 3x3