@@ -179,17 +179,20 @@ def write_morph_data(file_like, values, fnum=0):
179179 in binary write (`'wb'` mode, implementing the `write` method)
180180 values : array-like
181181 Surface morphometry values
182+
183+ Shape must be (N,), (N, 1), (1, N) or (N, 1, 1)
182184 fnum : int, optional
183185 Number of faces in the associated surface
184186 """
185187 magic_bytes = np .array ([255 , 255 , 255 ], dtype = np .uint8 )
186188
187- array = np .asarray (values ).astype ('>f4' ).squeeze ()
188- if len (array .shape ) > 1 :
189- raise ValueError ("Multi-dimensional values not supported" )
189+ vector = np .asarray (values )
190+ vnum = np .prod (vector .shape )
191+ if vector .shape not in ((vnum ,), (vnum , 1 ), (1 , vnum ), (vnum , 1 , 1 )):
192+ raise ValueError ("Invalid shape: argument values must be a vector" )
190193
191194 i4info = np .iinfo ('i4' )
192- if len ( array ) > i4info .max :
195+ if vnum > i4info .max :
193196 raise ValueError ("Too many values for morphometry file" )
194197 if not i4info .min <= fnum <= i4info .max :
195198 raise ValueError ("Argument fnum must be between {0} and {1}" .format (
@@ -199,9 +202,9 @@ def write_morph_data(file_like, values, fnum=0):
199202 fobj .write (magic_bytes )
200203
201204 # vertex count, face count (unused), vals per vertex (only 1 supported)
202- fobj .write (np .array ([len ( array ) , fnum , 1 ], dtype = '>i4' ))
205+ fobj .write (np .array ([vnum , fnum , 1 ], dtype = '>i4' ))
203206
204- fobj .write (array )
207+ fobj .write (vector . astype ( '>f4' ) )
205208
206209
207210def read_annot (filepath , orig_ids = False ):
0 commit comments