0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python で標準入力から行列形式のデータを読み込む

Posted at

概要

  • 競プロをやる際に,行列形式のデータを int 型で受け取る場面がよく出てくるのでメモ.
    • そのままコピペして使えます.
  • 動作確認環境
    • Ubuntu 20.04
    • Python 3.8.10
sample_input.txt
4
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
read_input.py
import numpy as np

def read_stdin():
	n = int(input())
	mat = np.array([list(map(int, input().split(' '))) for _ in range(n)])
	print(mat)
	return (n, mat)

  • 動作確認
python3 read_input.py < sample_input.txt

標準入力に関しては C 言語とかのほうが楽なんよ

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?