0
1

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 5 years have passed since last update.

pythonの配列の形の出力

Posted at

こんにちは

pythonを勉強したばかりの者です。
今のところはランダム数字の配列を作成するプログラミングを書いています。
ランダム数字は確かに出ていますが、希望した形になれませんでした。
書いたコードは下記のようになります。

import numpy as np

n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3: ')

data = [0]*n_zero + [1]*n_one + [2]*n_two + [3]*n_three
np.random.shuffle(data)
print(data)

出力結果は

Insert the amount of 0: 6
Insert the amount of 1: 2
Insert the amount of 2: 1
Insert the amount of 3: 2
[3, 0, 0, 0, 1, 0, 1, 0, 3, 0, 2]

自分が希望する結果はこのような形です。
30001010302

カンマと括弧なしの形は望ましい結果です。

よろしくお願いします。

0
1
3

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?