Numpy学习(二)

数组的属性

a = np.array([[1,2,3],[4,5,6]])
a.dtype#ndarray 对象的元素类型
a.size#数组元素的总个数,相当于 .shape 中 n*m 的值
a.shape#数组的维度,对于矩阵,n 行 m 列
a.T#转置
a.ndim #维数
dtype('int32')
6
(2, 3)
array([[1, 4],
       [2, 5],
       [3, 6]])
2

数组对象与数字相乘

import numpy as np
import random
a = [random.uniform(100.0,200.0) for i in range(50)]
print(a)
x = 6.8
b = []
for ele in a:
     b.append(ele * x )
np.array(b)

a的数据

[138.76256124676726, 167.4014849945554, 183.2618097606774, 140.28552635236318,
 196.2793194368658, 119.45538152931336, 128.52063627899943, 194.02787973206543, 
 146.93942441518053, 128.0571763650359, 102.76693126498671, 181.522402652962,
 175.10388440420343, 123.32313668218306, 147.35098178169505, 183.2197171416236, 
 181.23279374596746, 138.6092014153603, 169.62041600859158, 115.43421976083579, 
 176.94905370885215, 191.64580688340124, 159.45419172505413, 142.18301896495066, 
 106.29485725040658, 119.68138259856183, 109.94184832486721, 137.82009109585903, 
 110.876115523733, 123.17544043480028, 142.15154110331608, 115.30220728738217, 
 166.24456900252204, 137.68159251783908, 125.46876286480156, 178.8284542171566, 
 193.9797165341405, 196.34358509530517, 173.3480675021954, 136.18430605790428, 
 110.14721794492795, 175.35363236851325, 109.64709348107608, 100.72946768787372, 
 173.6059818085674, 114.4958848439768, 165.09675418259707, 170.60401662652998, 
 135.24284026611969, 156.48007798443683]

b的数据

array([ 943.58541648, 1138.33009796, 1246.18030637,  953.9415792 ,
       1334.69937217,  812.2965944 ,  873.9403267 , 1319.38958218,
        999.18808602,  870.78879928,  698.8151326 , 1234.35233804,
       1190.70641395,  838.59732944, 1001.98667612, 1245.89407656,
       1232.38299747,  942.54256962, 1153.41882886,  784.95269437,
       1203.25356522, 1303.19148681, 1084.28850373,  966.84452896,
        722.8050293 ,  813.83340167,  747.60456861,  937.17661945,
        753.95758556,  837.59299496,  966.6304795 ,  784.05500955,
       1130.46306922,  936.23482912,  853.18758748, 1216.03348868,
       1319.06207243, 1335.13637865, 1178.76685901,  926.05328119,
        749.00108203, 1192.40470011,  745.60023567,  684.96038028,
       1180.5206763 ,  778.57201694, 1122.65792844, 1160.10731306,
        919.65131381, 1064.06453029])

数组对象与数组对象相乘

a = [random.uniform(10.0,20.0) for i in range(50)]
b = [random.randint(1,10) for i in range(50)]
a = np.array(a)
b = np.array(b)
a * b
(a *b).sum()
array([143.14502002, 114.68181148,  14.14685251,  43.33125865,
        47.05622953, 108.66064707,  49.83548845,  55.26968559,
        82.76093247,  83.64557683,  46.76226903,  36.86022919,
        64.51966137, 164.40122929,  40.04168957,  24.15791414,
        94.1250113 , 152.30407675,  53.54655577,  66.58384958,
        27.64255806,  44.70881224, 107.02608109,  67.41974126,
        13.30444772,  38.4281846 ,  30.60925682,  16.81177149,
       113.172353  , 119.83506464,  77.89076441,  95.54856424,
        36.72984553,  65.59408455,  49.88259459,  40.194351  ,
       198.88690117,  90.14082991,  19.29066793,  18.26501902,
       101.44743047, 102.83058482,  76.16335996,  74.77755041,
        52.46746378, 129.69101907, 187.63072629, 141.54889903,
        33.23967068, 129.65357584])
3901.007376220184#两者相乘后的数据相加   

注意:两个数组对象一定要相同的格式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值