0
点赞
收藏
分享

微信扫一扫

关于 python 自己写 numpy

君心浅语 2022-02-07 阅读 35
import random

class numpy:
    def __init__(self):
        self.x = 5
        self.y = 5
        self.data = None

    def create_zone(self,x,y):
        self.x = x
        self.y = y
        l2 = []
        for y in range(0,self.y):
            l1 = []
            for x in range(0,self.x):
                l1.append(0)
            l2.append(l1)
        return l2

    def create_random_int(self,x,y,b,e):
        self.x = x
        self.y = y
        l2 = []
        for y in range(0,self.y):
            l1 = []
            for x in range(0,self.x):
                l1.append((random.randint(b,e)))
            l2.append(l1)
        return l2

    def create_random_float(self,x,y):
        self.x = x
        self.y = y
        l2 = []
        for y in range(0,self.y):
            l1 = []
            for x in range(0,self.x):
                l1.append((random.random()))
            l2.append(l1)
        return l2

    def dot(self,l1,l2):
        y2 = []
        self.x = len(l1[0])
        self.y = len(l1)
        for y in range(0, self.y):
            x1 = []
            for x in range(0, self.x):
                x1.append(l1[y][x] * l2[y][x])
            y2.append(x1)
        return y2
举报

相关推荐

0 条评论