Python Forum
matrix name including a variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matrix name including a variable
#4
well, based on the above materials, I'm trying to understand how to proceed. It's the first time I've the opportunity to use a dictionnary and I'm performing tests.

I need to go deeper to figure out how it works, but I'm still wondering if the dictonnary is dynamically linked to key values (I do not understand why the RAM is much lower - but the last lines seem to say it's not the case, or maybe it's not "getsizeof" I need to use)

Paul
import numpy as np
from sys import getsizeof

n = 1_000
#n = 10
m = 2
X = np.random.random((n,m))
Y = np.random.random((n,m))
Z = np.random.random((n,m))
MAT_DICT = {'abscissa': X, 'ordinate': Y, 'applicate': Z}
print("X RAM = {}".format(getsizeof(X)))
print("Y RAM = {}".format(getsizeof(Y)))
print("Z RAM = {}".format(getsizeof(Z)))
print("MAT_DICT RAM = {}".format(getsizeof(MAT_DICT)))

my_var = 'abscissa'
if my_var in MAT_DICT:
    print("'{}' is in MAT matrix".format(my_var))
else:
    print("'{}' is not in MAT matrix".format(my_var))

    
## add new key/value
theta = np.random.random((n,2*m))
MAT_DICT.update({'Theta': theta})

## access to a key and work with
extract_key = MAT_DICT["abscissa"]
check = np.min(np.absolute(X - extract_key))
print("diff = {}".format(check))


## now update of 'abcissa" values
extract_key = 2.*MAT_DICT["abscissa"]
MAT_DICT["abscissa"] = extract_key # solution 1

extract_key = 10.*MAT_DICT["ordinate"]
MAT_DICT.update({'ordinate': extract_key}) #solution2


## what append if I modify one array: is MAT_DIC changed (in another word is it dynamically linked?)
X = np.empty(0)
print(MAT_DICT)
Reply


Messages In This Thread
matrix name including a variable - by paul18fr - Nov-11-2019, 09:03 AM
RE: matrix name including a variable - by perfringo - Nov-11-2019, 09:25 AM
RE: matrix name including a variable - by paul18fr - Nov-12-2019, 11:20 AM
RE: matrix name including a variable - by paul18fr - Nov-16-2019, 03:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Clustering based on a variable and on a distance matrix flucoe 2 6,176 Dec-16-2018, 09:57 PM
Last Post: flucoe
  setup.py not including file in wheel camerondevine 0 2,876 Jan-12-2018, 02:17 AM
Last Post: camerondevine

Forum Jump:

User Panel Messages

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