Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read/Write binary file
#4
for 2d array, I'd use something like below

But you have a single dimension array, so you're way ahead of me on this.

import numpy as np
from scipy.ndimage.interpolation import rotate
import os

# make sure file can be found in script directory
os.chdir(os.path.abspath(os.path.dirname(__file__)))

def rotate_and_save(infilename, outfilename, rotation_angle_degrees=90):    
    orig_array = np.fromfile(infilename, dtype=np.int64)
    print(f"\noriginal array\n{orig_array}")
    new_array = rotate(orig_array, angle=rotation_angle_degrees)
    print(f"\nnew array\n{new_array}")
    np.tofile(outfilename, dtype=np.int64)

def main():
    # Use any desired angle
    rotate_and_save('channel_order.bin', 'rotated_channel_order.bin', 
        rotation_angle_degrees=180)

if __name__ == '__main__':
    main(
Reply


Messages In This Thread
Read/Write binary file - by deanhystad - Jan-31-2021, 10:39 PM
RE: Read/Write binary file - by Larz60+ - Feb-01-2021, 12:49 AM
RE: Read/Write binary file - by deanhystad - Feb-01-2021, 04:22 AM
RE: Read/Write binary file - by Larz60+ - Feb-01-2021, 10:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Last record in file doesn't write to newline gonksoup 3 404 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  How Write Part of a Binary Array? Assembler 1 340 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  Recommended way to read/create PDF file? Winfried 3 2,867 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,501 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,427 Nov-09-2023, 10:56 AM
Last Post: mg24
Question Special Characters read-write Prisonfeed 1 609 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  read file txt on my pc to telegram bot api Tupa 0 1,105 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,103 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,251 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,499 Jun-06-2023, 06:37 PM
Last Post: rajeshgk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020