0

DS, Numpy size and shape

Hi, I am running example code of DS course, Date manipulation section, Getting started with Numpy, Reshape part. Both array.size and array.shape return the same value - in the example case "90" Is it expected? Here is the code import numpy as np heights = [189, 170, 189, 163, 183, 171, 185, 168, 173, 183, 173, 173, 175, 178, 183, 193, 178, 173, 174, 183, 183, 180, 168, 180, 170, 178, 182, 180, 183, 178, 182, 188, 175, 179, 183, 193, 182, 183, 177, 185, 188, 188, 182, 185, 191] ages = [57, 61, 57, 57, 58, 57, 61, 54, 68, 51, 49, 64, 50, 48, 65, 52, 56, 46, 54, 49, 51, 47, 55, 55, 54, 42, 51, 56, 55, 51, 54, 51, 60, 62, 43, 55, 56, 61, 52, 69, 64, 46, 54, 47, 70] heights_and_ages = heights + ages # convert a list to a numpy array heights_and_ages_arr = np.array(heights_and_ages) print(heights_and_ages_arr.shape) print(heights_and_ages_arr.size)

7th Jan 2021, 9:22 AM
Ashot Terteryan
Ashot Terteryan - avatar
1 Antwort
0
Size = 90 Shape = (90,) These two are different. Size means the number of element in the array, so here since there are 45 presidents, and their height and age is 45 each, when we concatente them together, we will get 90. Meanwhile for the shape, it represents the number of rows and columns. (rows, cols) Since we have here only one-dimensional Numpy array, we will get (90,). (90,) means 90 rows and 1 column. If we make it a 2-dimensional array then our shape would be (90, 1).
16th Jan 2021, 3:24 AM
noteve
noteve - avatar