np.savetxt('MotionDataOut.txt',np.c_[x,y], fmt='%8.1f' )

The only needed input for savetxt is the output filename and the arrays it will output. Everything else is optional.

  • The first argument 'MotionDataOut.txt' is the output file name
  • The second option np.c_[x,y] . Because we are trying to write not one array but two in the file we need to package the two arrays into one. To do that we use the function c_. If we only needed to print one array we do not need to use .c_ we could just write the array for option. For example: np.savetxt('MotionDataOut.txt',x)
  • The third option used here is fmt='%1.1f' This option determines how the elements in the file are going to be displayed. The value of fmt here is a string equal to %5.1f. The letter f is for float. The number 8.1 The .1 part displays one decimal digit to the write of the decimal point. The 8. part is the minimum width. 8 in this case is more than any of the digits in each column. This will ensure that columns have the same widths and that the decimal points are aligned.

  • -->Try changing the fmt to 0.1, 0.2, 0.3,0.4
  • -->Try changing the fmt to 1.1,2.1,3.1,4.1,5.1

    Note how the output changes.