-1
import numpy as np
X = 10
matriz = []
for i in range(X):
matriz.append([])
for l in range(0,X):
for c in range(0,1):
matriz[l].append(input().split())
print(matriz)
matriz_nova = np.array(matriz)
-1
import numpy as np
X = 10
matriz = []
for i in range(X):
matriz.append([])
for l in range(0,X):
for c in range(0,1):
matriz[l].append(input().split())
print(matriz)
matriz_nova = np.array(matriz)
1
That’s what you got
>>> X = 10
>>> matriz = []
>>> for i in range(X):
... matriz.append([])
...
>>> for l in range(0, X):
... for c in range(0,1):
... matriz[l].append(input().split())
...
1 2 3 4 5 6 7 8 9 10
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9
>>> print(matriz)
[[['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']], [['1', '1', '1', '1', '1', '1', '1', '1', '1', '1']], [['2', '2', '2', '2', '2', '2', '2', '2', '2', '2']], [['3', '3', '3', '3', '3', '3', '3', '3', '3', '3']], [['4', '4', '4', '4', '4', '4', '4', '4', '4', '4']], [['5', '5', '5', '5', '5', '5', '5', '5', '5', '5']], [['6', '6', '6', '6', '6', '6', '6', '6', '6', '6']], [['7', '7', '7', '7', '7', '7', '7', '7', '7', '7']], [['8', '8', '8', '8', '8', '8', '8', '8', '8', '8']], [['9', '9', '9', '9', '9', '9', '9', '9', '9', '9']]]
>>> matriz_nova = np.array(matriz)
>>> matriz_nova
array([[['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']],
[['1', '1', '1', '1', '1', '1', '1', '1', '1', '1']],
[['2', '2', '2', '2', '2', '2', '2', '2', '2', '2']],
[['3', '3', '3', '3', '3', '3', '3', '3', '3', '3']],
[['4', '4', '4', '4', '4', '4', '4', '4', '4', '4']],
[['5', '5', '5', '5', '5', '5', '5', '5', '5', '5']],
[['6', '6', '6', '6', '6', '6', '6', '6', '6', '6']],
[['7', '7', '7', '7', '7', '7', '7', '7', '7', '7']],
[['8', '8', '8', '8', '8', '8', '8', '8', '8', '8']],
[['9', '9', '9', '9', '9', '9', '9', '9', '9', '9']]], dtype='<U2')
Change part of your code to
X = 10
matriz = []
for i in range(X):
matriz.append([])
for l in range(0, X):
for c in range(0,1):
matriz[l] += input().split() # A ALTERAÇÃO FOI AQUI !!!
print(matriz)
matriz_nova = np.array(matriz)
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9
0 0 0 0 0 0 0 0 0 0
>>> print(matriz)
[['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'], ['2', '2', '2', '2', '2', '2', '2', '2', '2', '2'], ['3', '3', '3', '3', '3', '3', '3', '3', '3', '3'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['5', '5', '5', '5', '5', '5', '5', '5', '5', '5'], ['6', '6', '6', '6', '6', '6', '6', '6', '6', '6'], ['7', '7', '7', '7', '7', '7', '7', '7', '7', '7'], ['8', '8', '8', '8', '8', '8', '8', '8', '8', '8'], ['9', '9', '9', '9', '9', '9', '9', '9', '9', '9'], ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']]
>>> matriz_nova = np.array(matriz)
>>> matriz_nova
array([['1', '1', '1', '1', '1', '1', '1', '1', '1', '1'],
['2', '2', '2', '2', '2', '2', '2', '2', '2', '2'],
['3', '3', '3', '3', '3', '3', '3', '3', '3', '3'],
['4', '4', '4', '4', '4', '4', '4', '4', '4', '4'],
['5', '5', '5', '5', '5', '5', '5', '5', '5', '5'],
['6', '6', '6', '6', '6', '6', '6', '6', '6', '6'],
['7', '7', '7', '7', '7', '7', '7', '7', '7', '7'],
['8', '8', '8', '8', '8', '8', '8', '8', '8', '8'],
['9', '9', '9', '9', '9', '9', '9', '9', '9', '9'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']], dtype='<U1')
I hope it helps
Browser other questions tagged python-3.x
You are not signed in. Login or sign up in order to post.
Want to work with matrices? Read here. here and here
– Solkarped