How to include a value in a matrix by separating a digit in each column?

Asked

Viewed 30 times

0

I developed a program that, when informing a value, this value is allocated in all columns of the row, returning me an array like this:

array([[0, 0, 0],
    [233, 233, 233],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0]])]

However, I would like it to be separated by digits, so:

array([[0, 0, 0],
        [2, 3, 3],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])]

That is, when reporting a value 233 I would like it to be separated by unit and, each unit populating a column. Could you assist me? I tried to make some changes to the code, but I didn’t reach my goal.

My code:

LINHAS = 6
COLUNAS = 3
ab = numpy.zeros((LINHAS, COLUNAS), dtype=int)

while True:
  index += 1
  ac = int(input('Insira um numero de 3 digitos:')
  ab[index] = ac

1 answer

2


If I understand correctly what you want is to type a number of three digits and the program plays each digit in a column, this for each row of the matrix. Right? Then your show could be like this:

import numpy

LINHAS = 6
COLUNAS = 3
ab = numpy.zeros((LINHAS, COLUNAS), dtype=int)
for i in range(LINHAS):
    ac = input('Insira um numero de 3 digitos:')
    ab[i] = list(ac)

print(ab)
  • vlw, I’ve been wanting to do just that

  • just a suggestion, be more specific in what you want the program to do when you ask a question, because there’s a better chance you’ll get the answer you’re looking for. Thanks!

  • Draw, leave it :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.