how to view sparse matrices outside python environment - python

I am working with sparse matrices which are 11685 by 85730 . I am able to store it only as a .pickle file . I want to view the file outside the python environment also . I tried saving as a .txt and .csv files but they are of no help . Can anybody suggest a suitable format and library so that I can view those matrices outside the python environment .

Python allows you to write to many formats that are readable outside of python. .csv is one format, but there are also HDF5 and netcdf4 among others (those are meant to store array data though).
http://code.google.com/p/netcdf4-python/
http://code.google.com/p/h5py/
Or you could save them in a matlab readable format:
http://docs.scipy.org/doc/scipy/reference/tutorial/io.html
What you use should depend on how you plan on accessing the data outside of python.

Related

how to change field variable/cell values in vti file with python script

I have a vti file which contains certain geometry with hexagonal mesh. After a loading step a field variable name "concentration" changes and must be changed back zero. There is one possibility in paraview by hard way. Can any body share a way how to open, edit a field variable and overwrite a vti file with python.
Thanks.
You can use vtk python module to do that.
read with vtkXMLImageDataReader
Get the array to modify array = reader.GetOutput().GetCellData().GetArray("concentration")
modify the array values by index: array.InsertTuple(i, 0)
write back with vtkXMLImageDataWriter
See the read/write example
That is the native VTK solution. There is some other ways, as using numpy to modify the data array, or do it in ParaView python scripting

HDF5 and Python: Automatic export of an object

I'm new to the HDF5 file format and have been experimenting successfully in Python with h5py. Now its time to store real data.
I will need to store a list of objects, where each object can be one of several types and each type will have a number of arrays and strings. The critical part is that the list of objects will be different for each file, and there will be hundreds of files.
Is there a way to automatically export an arbitrary, nested object into (and back from) an HDF5 file? I'm imagining a routine that would automatically span the hierarchy of a nested object and build the same hierarchy in the HDF5 file.
I've read through the H5PY doc and don't see any spanning routines. Furthermore, google and SO searches are (strangely) not showing this capability. Am i missing something or is there another way to look at this.

HDF5: alias for data-keys in caffe

I'm trying to load HDF5 data for my caffe-net as input data. So far I can create those hdf5-databases and the list file. I also read the simple example in https://ceciliavision.wordpress.com/2016/03/21/caffe-hdf5-layer/. There is stated that the dataset keys are also the names of the data-layer in caffe. But what I want is a to give them kind of aliases in caffe, is that possible? The reason is that I have two hdf5-DB with the same dataset-structure inside, so also the same dataset-keys. Is there a name-clash if I load both hdf5-DB in the same net and if so can I change the names without changing the hdf5-DB itself?
Thanks for help!

How to extract data from Matlab .fig files in Python?

If I have some X vs Y data saved in a Matlab .fig file, is there a way to extract that data in Python? I've tried using the method shown in a previous discussion, but this does not work for me. I have also tried to open the files using h5py and PyTables, since .mat files are actually HDF5 files now, but this results in an error where a valid file signature can't be found.
Currently I'm trying to do this with the Anaconda distribution of Python 3.4.
EDIT: I managed to figure out something that works, but I don't know why. This has me worried something might break in the future and I won't be able to debug it. If anyone can explain why this works, but the method in the old discussion doesn't I'd really appreciate it.
from scipy.io import loadmat
d = loadmat('linear.fig', squeeze_me=True, struct_as_record=False)
x = d['hgS_070000'].children.children.properties.XData
y = d['hgS_070000'].children.children.properties.YData
The best way I can think of is using any of the Matlab-Python bridge (such as pymatbridge).
You can call Matlab code directly on python files and transform the data from one to the other. You could use some Matlab code to load the fig and extract the data and then convert the numerical variables to python arrays (or numpy arrays) easily.

Any way to get a figure from Python's matplotlib into Matlab?

I'm processing some data for a research project, and I'm writing all my scripts in python. I've been using matplotlib to create graphs to present to my supervisor. However, he is a die-hard MATLAB user and he wants me to send him MATLAB .fig files rather than SVG images.
I've looked all over but can't find anything to do the job. Is there any way to either export .fig files from matplotlib, convert .svg files to .fig, or import .svg files into MATLAB?
Without access to (or experience with matlab) this is going to be a bit tricky. As Amro stated, .fig files store the underlying data, and not just an image, and you're going to have a hard time saving .fig files from python. There are however a couple of things which might work in your favour, these are:
numpy/scipy can read and write matlab .mat files
the matplotlib plotting commands are very similar to/ based on the matlab ones, so the code to generate plots from the data is going to be nearly identical (modulo round/square brackets and 0/1 based indexing).
My approach would be to write your data out as .mat files, and then just put your plotting commands in a script and give that to your supervisor - with any luck it shouldn't be too hard for him to recreate the plots based on that information.
If you had access to Matlab to test/debug, I'm sure it would be possible to create some code which automagically created .mat files and a matlab .m file which would recreate the figures.
There's a neat list of matlab/scipy equivalent commands on the scipy web site.
good luck!

Categories

Resources