Python3 - Numpy 练习题

import numpy as np

print("Create an array of 10 zeros")
print(np.zeros(10))

print("Create an array of 10 ones")
print(np.ones(10))

print("Create an array of 10 fives")
print(np.ones(10)*5)
print(np.zeros(10) + 5)

print("Create an array of the integers from 10 to 50")
print(np.arange(10,51))

print("Create an array of all the even integers from 10 to 50")
arr = np.arange(10,51)
print(arr[arr % 2 == 0])
print(np.arange(10,51,2))

print("Create a 3x3 matrix with values ranging from 0 to 8")
print(np.arange(9).reshape(3,3))

print("Create a 3x3 identity matrix")
print(np.eye(3))

print("Use NumPy to generate a random number between 0 and 1")
print(np.random.rand(1))

print("Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution")
print(np.random.randn(25))

print("Create an array of 20 linearly spaced points between 0 and 1")
print(np.linspace(0,1,20))

print("Create a 2-d array 5 x 5")
print(np.arange(1,26).reshape(5,5))

print("Get the sum of all the values")
print(np.sum(np.arange(1,26)))

print("Get the standard deviation of the values")
print(np.std(np.arange(1,26)))

print("Get the sum of all the columns")
arr = np.arange(1,26).reshape(5,5)
print(arr.sum(axis=0))

结果如下:
在这里插入图片描述
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值