Python Forum
Get an array out of a dict
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get an array out of a dict
#1
Hello,

I am trying to extract some data from a dict.

I am using the following code
def get_set_from_UNV_file (filePath,setNo,setName,timeTable,volumeVelocityTable):
	
	UNVfile=pyuff.UFF(filePath)
	UNVdata=UNVfile.read_sets(setNo)
	
	
	print (UNVdata['id1'])
	print("type: ",type(UNVdata['id1']))
	setName=UNVdata['id1']
	
	
	print (UNVdata['x'])
	print ("type: ",type(UNVdata['x']))
	timeTable = UNVdata['x']
	
	
	print (UNVdata['data'])
	print ("type: ",type(UNVdata['data']))
	volumeVelocityTable=UNVdata['data']
	


if __name__ == "__main__":
	fPath="C:\\Users\\ofa\\Desktop\\test\\Sample_UFF58_ascii.uff"
	
	valuesX=[]
	valuesY=[]
	name="tuto"
	print (get_set_from_UNV_file(fPath,0,name,valuesX,valuesY))
	print ("fPath: ",fPath)
	print ("name: ",name)
	print ("valuesX: ",valuesX)
	print ("valuesY: ",valuesY)
The output is

Output:
Input data: {'type': 58, 'binary': 0, 'id1': 'Mic 01.0Scalar', 'id2': 'NONE', 'id3': '18-Apr-16 13:49:58', 'id4': 'NONE', 'id5': 'NONE', 'func_type': 1, 'func_id': 0, 'ver_num': 0, 'load_case_id': 0, 'rsp_ent_name': 'Mic 01', 'rsp_node': 0, 'rsp_dir': 1, 'ref_ent_name': 'NONE', 'ref_node': 0, 'ref_dir': 0, 'ord_data_type': 2, 'num_pts': 79292, 'abscissa_spacing': 1, 'abscissa_min': 0.0, 'abscissa_inc': 1.52588e-05, 'z_axis_value': 0.0, 'abscissa_spec_data_type': 17, 'abscissa_len_unit_exp': 0, 'abscissa_force_unit_exp': 0, 'abscissa_temp_unit_exp': 0, 'abscissa_axis_lab': 'time', 'abscissa_axis_units_lab': 's', 'ordinate_spec_data_type': 21, 'ordinate_len_unit_exp': 0, 'ordinate_force_unit_exp': 0, 'ordinate_temp_unit_exp': 0, 'ordinate_axis_lab': 'Pressure', 'ordinate_axis_units_lab': 'Pa', 'orddenom_spec_data_type': 0, 'orddenom_len_unit_exp': 0, 'orddenom_force_unit_exp': 0, 'orddenom_temp_unit_exp': 0, 'orddenom_axis_lab': 'NONE', 'orddenom_axis_units_lab': 'NONE', 'z_axis_spec_data_type': 0, 'z_axis_len_unit_exp': 0, 'z_axis_force_unit_exp': 0, 'z_axis_temp_unit_exp': 0, 'z_axis_axis_lab': 'NONE', 'z_axis_axis_units_lab': 'NONE', 'x': array([ 0.00000000e+00, 1.52588000e-05, 3.05176000e-05, ..., 1.20985499e+00, 1.20987025e+00, 1.20988551e+00]), 'data': array([-0.0147553 , -0.0172957 , -0.0166101 , ..., 0.00722655, 0.00044363, -0.00431469])} variable: Mic 01.0Scalar type: <class 'str'> variable: [ 0.00000000e+00 1.52588000e-05 3.05176000e-05 ..., 1.20985499e+00 1.20987025e+00 1.20988551e+00] type: <class 'numpy.ndarray'> variable: [-0.0147553 -0.0172957 -0.0166101 ..., 0.00722655 0.00044363 -0.00431469] type: <class 'numpy.ndarray'> None fPath: C:\Users\ofa\Desktop\test\Sample_UFF58_ascii.uff name: tuto valuesX: [] valuesY: []
I know I should use nd arrays but I couldn't do it, how can I know the size before?
and how can I make a copy of the arrays from the dict.
Something else I don't understand is why the str name is not modified.

Thank you.
Reply


Forum Jump:

User Panel Messages

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