以下のような構造化配列から
python
1import numpy as np 2 3sprite_dtype = np.dtype([ 4 ('x', float, ), 5 ('y', float, ), 6 ('visible', bool, ), 7]) 8 9sprites = np.array( 10 [ 11 (0, 1, False), 12 (2, 3, True), 13 (4, 5, True), 14 (6, 7, False), 15 ], 16 dtype=sprite_dtype 17) 18 19print(sprites) # [(0., 1., False) (2., 3., True) (4., 5., True) (6., 7., False)]
以下のような配列(numpy配列,pythonのlist,tupleでもいい)またはそれを作れるようなiteratorを得る方法を知ってる方おられませんか?
python
1[0., 1., 2., 3., 4., 5., 6., 7., ]
numpyのravel()
とflat
を試してはみたのですが平坦化はしてくれませんでした。
python
1print(sprites[['x', 'y']].ravel()) # [(0., 1.) (2., 3.) (4., 5.) (6., 7.)] 2print([*sprites[['x', 'y']].flat]) # [(0., 1.), (2., 3.), (4., 5.), (6., 7.)]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/19 16:14
2020/01/20 10:16