简体   繁体   中英

len(n) x len(m) array in NumPy

n = ' AAADDDEEE'
m = ' AADDDEB'

How to create numpy of dimensions len(n) x len(m) where n is the first row, m is first column and all the other entries are empty

ie

  A A A D D D E E E 
A [][][][][][][][][]
A [][][][][][][][][]
D [][][][][][][][][]
D [][][][][][][][][]
D [][][][][][][][][]
E [][][][][][][][][]
B [][][][][][][][][]

I was trying something along the lines of

import numpy as np
print np.array(list(n),list(m))

but it only takes on argument . . . i'm not sure how to exactly go about this.

>>> arr = np.empty((len(m), len(n)), dtype=str)
>>> arr.fill('')
>>> arr[0] = list(n)
>>> arr[:,0] = list(m)
>>> arr
array([['A', 'A', 'A', 'D', 'D', 'D', 'E', 'E', 'E'],
       ['A', '', '', '', '', '', '', '', ''],
       ['D', '', '', '', '', '', '', '', ''],
       ['D', '', '', '', '', '', '', '', ''],
       ['D', '', '', '', '', '', '', '', ''],
       ['E', '', '', '', '', '', '', '', ''],
       ['B', '', '', '', '', '', '', '', '']], 
      dtype='|S1')
>>> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM