fromfile

Loading every nth element with numpy.fromfile [duplicate]

99封情书 提交于 2020-03-24 00:29:23
问题 This question already has an answer here : Read binary flatfile and skip bytes (1 answer) Closed 19 days ago . I want to create a numpy array from a binary file using np.fromfile . The file contains a 3D array, and I'm only concerned with a certain cell in each frame. x = np.fromfile(file, dtype='int32', count=width*height*frames) vals = x[5::width*height] The code above would work in theory, but my file is very large and reading it all into x causes memory errors. Is there a way to use

readinto() replacement?

不问归期 提交于 2020-01-14 14:37:54
问题 Copying a File using a straight-forward approach in Python is typically like this: def copyfileobj(fsrc, fdst, length=16*1024): """copy data from file-like object fsrc to file-like object fdst""" while 1: buf = fsrc.read(length) if not buf: break fdst.write(buf) (This code snippet is from shutil.py, by the way). Unfortunately, this has drawbacks in my special use-case (involving threading and very large buffers) [Italics part added later] . First, it means that with each call of read() a new

python bitarray to and from file

旧时模样 提交于 2020-01-02 06:18:32
问题 I'm writing a large bitarray to a file using this code: import bitarray bits = bitarray.bitarray(bin='0000011111') #just an example with open('somefile.bin', 'wb') as fh: bits.tofile(fh) However, when i attempt to read this data back using: import bitarray a = bitarray.bitarray() with open('somefile.bin', 'rb') as fh: bits = a.fromfile(fh) print bits it fails with 'bits' being a NoneType. What am i doing wrong? 回答1: I think "a" is what you want. a.fromfile(fh) is a method which fills a with

How to set FromFile location in Powershell?

两盒软妹~` 提交于 2019-12-20 07:17:13
问题 I am preparing a script, which needs to use some images from same folder as the script. The images are to be shown on WinForms GUI. $imgred = [System.Drawing.Image]::FromFile("red.png") When I run the ps1 script manually from the folder just by clicking, it loads images and shows them. Unfortuantely I do not remember exactly how I set up this, but as far as I can, it was just the default program to use for ps1 files. When I run the script from a cmd file (to hide the cmd window), it also

Extract specific bytes from a binary file in Python

会有一股神秘感。 提交于 2019-12-10 20:14:55
问题 I have very large binary files with x number of int16 data points for y sensors, along with headers with some basic info. The binary file is written as y values for each sample time up to x samples, then another set of readings and so on. If I want all of the data, I am using numpy.fromfile() which works really nice and fast. However, if I only want a subset of sensor data or only specific sensors, I currently have a hideous double for loop, using file.seek() , file.read() , and struct.unpack

python bitarray to and from file

大兔子大兔子 提交于 2019-12-05 11:57:13
I'm writing a large bitarray to a file using this code: import bitarray bits = bitarray.bitarray(bin='0000011111') #just an example with open('somefile.bin', 'wb') as fh: bits.tofile(fh) However, when i attempt to read this data back using: import bitarray a = bitarray.bitarray() with open('somefile.bin', 'rb') as fh: bits = a.fromfile(fh) print bits it fails with 'bits' being a NoneType. What am i doing wrong? I think "a" is what you want. a.fromfile(fh) is a method which fills a with the contents of fh: it doesn't return a bitarray. >>> import bitarray >>> bits = bitarray.bitarray(

How to set FromFile location in Powershell?

谁说胖子不能爱 提交于 2019-12-02 10:45:07
I am preparing a script, which needs to use some images from same folder as the script. The images are to be shown on WinForms GUI. $imgred = [System.Drawing.Image]::FromFile("red.png") When I run the ps1 script manually from the folder just by clicking, it loads images and shows them. Unfortuantely I do not remember exactly how I set up this, but as far as I can, it was just the default program to use for ps1 files. When I run the script from a cmd file (to hide the cmd window), it also loads them. But when I open with Powershell IDE and run it, I get errors and no icons are shown on my GUI.

Loading a picture file Image.FromFile VS FileStream

自闭症网瘾萝莉.ら 提交于 2019-11-29 10:37:21
I must admit that I never understood what are the streams are all about- I always thought it's an internet thing. But now I run into a code that used a stream to load a file localy and I wonder if there is advantage for using a stream over... well the way I always loaded files: private void loadingfromStream() { DirectoryInfo dirInfo = new DirectoryInfo("c:/"); FileInfo[] fileInfoArr = dirInfo.GetFiles(); FileInfo fileInfo = fileInfoArr[0]; // creating a bitmap from a stream FileStream fileStream = fileInfo.OpenRead(); Bitmap bitmap = new Bitmap(fileStream); Image currentPicture = (Image

How do I add an image to a label?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 14:21:50
问题 I have to add image to my label, but I can't find solution how to do this. I'm trying by use this: InitializeComponent(); url = Directory.GetCurrentDirectory() + @"/Cards/cardSkin.png"; mylabel.Background = new ImageBrush(new BitmapImage(new Uri(url))); I don't know even if I'm using this right, I just copied this from others project what we did with class. Anyway, I tried to create Image img = Image.FromFile("YourFile.bmp"); but I don't why, .FromFile wasn't working for me. Anyone of you

Loading a picture file Image.FromFile VS FileStream

…衆ロ難τιáo~ 提交于 2019-11-28 04:02:23
问题 I must admit that I never understood what are the streams are all about- I always thought it's an internet thing. But now I run into a code that used a stream to load a file localy and I wonder if there is advantage for using a stream over... well the way I always loaded files: private void loadingfromStream() { DirectoryInfo dirInfo = new DirectoryInfo("c:/"); FileInfo[] fileInfoArr = dirInfo.GetFiles(); FileInfo fileInfo = fileInfoArr[0]; // creating a bitmap from a stream FileStream