[Deep Learning Experiment] Simple usage of NumPy

Table of contents

1. Introduction to NumPy

1. Official website

2. Official Tutorial

2. Experimental content

1. Import the numpy library

2. Print the version number

3. arange function

4. array function

5. reshape function

6. Matrix dot multiplication (element-wise multiplication)

7. Matrix multiplication


 

 

 

1. Introduction to NumPy

NumPy is a Python library commonly used in scientific computing, especially in deep learning and machine learning.

1. Official website

NumPyhttps://numpy.org/e418c18aa37d485eac6ee6d109092437.png

 

2. Official Tutorial

NumPy: Absolute Basics for Beginners — NumPy v1.25 Manual https://numpy.org/doc/stable/user/absolute_beginners.html6e60456300b7497e825ea8041aec0d34.png

 

 

2. Experimental content

1. Import the numpy library

  • Import numpy library (you should follow the standard NumPy conventions).

        Import the numpy library (should follow standard NumPy conventions).

import numpy as np

 

2. Print the version number

  • Print the version number of NumPy.

        Print the version number of NumPy.

print(np.__version__)

 

3. arange function

  • Use the arange function to generate 10 elements from 0 to 9 and store them in a variable named ndarray.

        Use the arange function to generate 10 elements from 0 to 9 and store them in a variable named ndarray.

ndarray = np.arange(10)
print(ndarray)

 

4. arrayfunction

  • Utilize the array function to convert data in Python list format into an equivalent ndarray named ndarray1.

        Utilize arraya function to convert data in Python list format to an equivalent ndarray named ndarray1.

ndarray1 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
print(ndarray1)

 

5. reshape function

  • Reshape the ndarray and the ndarray1 into a 2-row by 5-column array.

        Transform ndarray and ndarray1 into 2 row by 5 column arrays.

ndarray = ndarray.reshape(2, 5)
ndarray1 = ndarray1.reshape(2, 5)
print(ndarray)
print(ndarray1)

 

6.  Matrix point multiplication ( element-wise multiplication)

  • Calculate the elementwise product of ndarray and ndarray1 using the * operator, and print the result

        Computes the element-wise product of ndarray and ndarray1 using the * operator and prints the result

result = ndarray * ndarray1
print(result)

 

7. Matrix multiplication

  • Calculate the matrix product of ndarray and ndarray1 using the @ operator, and print the result. You need to use the T attribute to perform a transpose operation on ndarray1.

        Computes the matrix product of ndarray and ndarray1 using the @ operator and prints the result. The transpose operation needs to be performed on ndarray1 using the T attribute.

result1 = ndarray @ ndarray1.T
print(result1)

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_63834988/article/details/132612496