Decode unknown encoding for numpy array - numpy

Can anybody help me decode this?
{'py/object': 'numpy.ndarray',
'values': 'eJxjYGBgkGnVczQGAl07DcezZ86cmeCo7Dhr5syZJ6fLgelSHwnHNCBY5isMlpdYxQdWfz2aA6I+mhmsTvDAPwcQ/TDvh4PHwyqRS6mfHQptua5PvvIOTCc3vwDTwVWPHeRbXwdqPLsHpn9MueEAVL7uefdlh8NfNWL8Oc87AJUt3rDgBJgWWH/YAehMhgX++8G0wo4dEP70zWD6gMJ6hy9/r1S8PLrCwbzTMUF1/2IwP/PBPIesPSWTJZbNAKtrODbZQd2QY42MUT+Yz/C8wyF1VUJI0LxmB1YTQTObGfUO4dEb97+5X+EQaqC1UnhHscM/519vX/fkO2wV/X363eUMB8UNRRkTTyc7HDy10HVbcrzDWWu/ixNlIh2a2/5x6h0IdjgnGXhLeo2/g07ti6Zf7zwcfqyayrn/jjNU3B4qbgEVN4aK6ztsUDgbYXJWw2HDv/OJ++4oO1z7b3lm+nF5h33fzkxicJV0qDoa3G/CIeLgfPLJlXMT+B0cr764yuDK6fD9mbmPCQeLw/l5p6+o/Phvn3WXbev9qJ/2bmw7uw1cv9hDxN/bAwBaO9+O',
'shape': [61],
'dtype': 'float64',
'byteorder': '<'}
Many thanks - looked through several encode/decode functions and haven't had any luck yet.

Related

How can I plot a Chord diagram from my pandas df?

I'm trying to create a Chord Diagram that will represent the relation between two different users, exactly as you can see on the image below;
I read the Plotly tutorial https://plotly.com/python/v3/filled-chord-diagram/ but unfortunately, it's not working well;
I would like to know if someone has experience with this chart or has a good reference that I can use to understand how to implement it
Below is the sample data:
import pandas as pd
data_dict=[{'users_relation': '5ddd6939<->f3c525e3',
'user_0_idx': '5ddd6939',
'user_1_idx': 'f3c525e3',
'score': 0.8205884909272926,
'time_order': 0},
{'users_relation': '5ddd6939<->825b50dc',
'user_0_idx': '5ddd6939',
'user_1_idx': '825b50dc',
'score': 0.7253207649551456,
'time_order': 0},
{'users_relation': 'f3c525e3<->825b50dc',
'user_0_idx': 'f3c525e3',
'user_1_idx': '825b50dc',
'score': 0.7933140542847614,
'time_order': 0}]
chord_diag_data=pd.DataFrame.from_dict(data_dict)
Any help/suggestion will be really appreciated and welcome;
**Please note, you can ignore the "time" part, as my focus in building the chart;
Regards,

Cupy structure array subscript

How do I subscript a structured cupy array. I can't find the document about it...
arr = cp.zeros(shape=(100,), dtype=cp.dtype([('t', '<f4'), ('tri', '<i4'), ('u', '<f4'), ('v', '<f4')]))
# numpy...
arr[...]['tri']
# cupy
????
Currently, CuPy does not support structured arrays. In fact, only boolean and numeric ones are listed as the supported data types in the Overview documentation.

Irregular Numpy matrix

In Numpy, it appears that the matrix can simply be a nested list of anything not limited to numbers. For example
import numpy as np
a = [[1,2,5],[3,'r']]
b = np.matrix(a)
generates no complaints.
What is the purpose of this tolerance when list can treat the object that is not a matrix in the strict mathematical sense?
What you've created is an object dtype array:
In [302]: b=np.array([[1,2,5],[3,'r']])
In [303]: b
Out[303]: array([[1, 2, 5], [3, 'r']], dtype=object)
In [304]: b.shape
Out[304]: (2,)
In [305]: b[0]
Out[305]: [1, 2, 5]
In [306]: b[1]=None
In [307]: b
Out[307]: array([[1, 2, 5], None], dtype=object)
The elements of this array are pointers - pointers to objects else where in memory. It has a data buffer just like other arrays. In this case 2 pointers, 2
In [308]: b.__array_interface__
Out[308]:
{'data': (169809984, False),
'descr': [('', '|O')],
'shape': (2,),
'strides': None,
'typestr': '|O',
'version': 3}
In [309]: b.nbytes
Out[309]: 8
In [310]: b.itemsize
Out[310]: 4
It is very much like a list - which also stores object pointers in a buffer. But it differs in that it doesn't have an append method, but does have all the array ones like .reshape.
And for many operations, numpy treats such an array like a list - iterating over the pointers, etc. Many of the math operations that work with numeric values fail with object dtypes.
Why allow this? Partly it's just a generalization, expanding the concept of element values/dtypes beyond the simple numeric and string ones. numpy also allows compound dtypes (structured arrays). MATLAB expanded their matrix class to include cells, which are similar.
I see a lot of questions on SO about object arrays. Sometimes they are produced in error, Creating numpy array from list gives wrong shape.
Sometimes they are created intentionally. pandas readily changes a data series to object dtype to accommodate a mix of values (string, nan, int).
np.array() tries to create as high a dimension array as it can, resorting to object dtype only when it can't, for example when the sublists differ in length. In fact you have to resort to special construction methods to create an object array when the sublists are all the same.
This is still an object array, but the dimension is higher:
In [316]: np.array([[1,2,5],[3,'r',None]])
Out[316]:
array([[1, 2, 5],
[3, 'r', None]], dtype=object)
In [317]: _.shape
Out[317]: (2, 3)

NumPy argmax and structured array error: expected a readable buffer object

I got the following error while using NumPy argmax method. Could some one help me to understand what happened:
import numpy as np
b = np.zeros(1, dtype={'names':['a','b'], 'formats': ['i4']*2})
b.argmax()
The error is
TypeError: expected a readable buffer object
While the following runs without a problem:
a = np.zeros(3)
a.argmax()
It seems the error dues to the structured array. But could you anyone help to explain the reason?
Your b is:
array([(0, 0)], dtype=[('a', '<i4'), ('b', '<i4')])
I get a different error message with argmax:
TypeError: Cannot cast array data from dtype([('a', '<i4'), ('b', '<i4')]) to dtype('V8') according to the rule 'safe'
But this works:
In [88]: b['a'].argmax()
Out[88]: 0
Generally you can't do math operations across the fields of a structured array. You can operate within each field (if it is numeric). Since the fields could be a mix of numbers, strings and other objects, so there's been no effort to handle special cases where such operations might make sense.
If you really must to operations across the fields, try a different view, eg:
In [94]: b.view('<i4').argmax()
Out[94]: 0

Reading in single str column with loadtxt

I have the file called mda_bk-adds-gro.inp:
# -*- mode:python -*-
0.5, 0.5, 0.5, walp_fixed.gro
0.5, 0.5, 0.4, walp.gro
I think I'll read the numbers and the the word separately. I've succeded in parsing the numbers:
loadtxt('mda_bk-adds-gro.inp', comments='#', delimiter=',', usecols=(0,1,2))
But can't read in just words:
loadtxt('mda_bk-adds-gro.inp', comments='#', delimiter=',', dtype=[('fileName', '|S100')], usecols=(3))
it gives an error:
TypeError: 'int' object is not iterable
So my question is - how do I read the forth column with loadtxt provided the column is str?
You get the TypeError because (3) is not a tuple, but just a parenthesized int-typed expression. Try usecols=(3,) instead.
See the comments at this issue for an explanation why this is so.