Home Backend Development Python Tutorial Tips and tricks for viewing numpy versions

Tips and tricks for viewing numpy versions

Jan 19, 2024 am 10:53 AM
View tips Tips numpy version

Tips and tricks for viewing numpy versions

numpy is a very commonly used mathematics library in Python. It is widely used in the field of scientific computing and supports a large number of numerical calculations, linear algebra, random number generation, Fourier transform and other functions. When using numpy for mathematical calculations, it is often necessary to determine the numpy version and its characteristics, and make different optimization and algorithm selections for different versions of numpy. This article will introduce tips and tricks for checking numpy version, and how to better use numpy by detecting numpy version information.

1. How to view the numpy version

There are many built-in functions and properties in numpy that can be used to obtain numpy version information. The following will introduce several commonly used methods to check the numpy version.

  1. Use numpy.version attribute

There is a version attribute in numpy, which can be used to obtain detailed information of the current numpy version, including version number and Git commit hash value , compiler information, etc. The code example is as follows:

1

2

import numpy as np

print(np.version.version)

Copy after login

The output result is as follows:

1

1.20.1

Copy after login
Copy after login
  1. Use numpy.__version__ attribute

In addition to the version attribute, numpy also A __version__ attribute is provided, whose default value is a string representation of the current numpy version. This attribute is also one of the common ways to determine version information in numpy. The code example is as follows:

1

2

import numpy as np

print(np.__version__)

Copy after login

The output result is the same as the previous example:

1

1.20.1

Copy after login
Copy after login
  1. Use numpy.show_config function

If you need to view more detailed numpy compilation and build information, you can use the numpy.show_config function. This function will display the various compilers, linkers, and libraries used by numpy when building, including the C compiler, CBLAS library, LAPACK library, etc. Its code example is as follows:

1

2

import numpy as np

np.show_config()

Copy after login

The output result is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

blas_mkl_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

 

blis_info:

    NOT AVAILABLE

 

openblas_info:

    NOT AVAILABLE

 

lapack_mkl_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

 

lapack_opt_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

 

lapack_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

 

mkl_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

 

blas_opt_info:

    libraries = ['mkl_rt']

    library_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/lib/intel64']

    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]

    include_dirs = ['C:/Program Files (x86)/Intel/oneAPI/mkl/2021.1.1/include']

...(输出结果省略)

Copy after login

Through the above three methods, you can check the specific version and compilation information of numpy, and find out whether the version of numpy is suitable for different applications. The numpy version corresponding to the project, as well as the selection of appropriate numpy algorithms and methods, are of great significance.

2. Application of numpy version information

After clarifying the numpy version information, when using numpy, you can select appropriate algorithms and methods for different versions to achieve the optimal Optimization effect and performance improvement. For example, in numpy versions 1.20 and above, higher-level functions can be used to automatically handle NaN values ​​to avoid exceptions when the program is running. At the same time, some efficient optimization algorithms are used, and the performance has also been greatly improved. In lower versions of numpy, you may need to manually handle NaN values ​​and exceptions, and use some simple algorithms to improve the stability and performance of the program.

The following is a simple example showing how to use numpy version information to select the optimal algorithm.

Suppose we need to calculate the product of a 10000×10000 matrix. We can calculate this task in two ways. One method is to use the numpy.dot() function, which calculates the dot product of two matrices by calling the dgemm subroutine in the BLAS library. It also supports multi-threading and vectorization calculations, and the calculation speed is very fast. Another method is to use the numpy.multiply() function to multiply the two matrices element by element, and then sum the results to obtain the dot product. The implementation of this method is relatively simple, but the performance is poor.

The following code compares the calculation time of the two algorithms:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

import numpy as np

import time

 

A = np.random.rand(10000, 10000)

B = np.random.rand(10000, 10000)

 

# 方法1:使用numpy.dot函数

start_time = time.time()

C = np.dot(A, B)

end_time = time.time()

print("方法1计算时间:", end_time - start_time)

 

# 方法2:使用numpy.multiply函数

start_time = time.time()

C = np.multiply(A, B).sum()

end_time = time.time()

print("方法2计算时间:", end_time - start_time)

Copy after login

The output results are as follows:

1

2

方法1计算时间: 3.94059681892395

方法2计算时间: 9.166156768798828

Copy after login

As you can see, the calculation speed of using numpy.dot() It is almost 2.5 times faster than using numpy.multiply(). From this, it can be concluded that when the numpy version is compatible, the numpy.dot() algorithm should be preferred for better performance and shorter calculation time.

Conclusion

This article introduces several methods for viewing numpy versions, and also introduces the application of different algorithms and methods for different numpy versions. In actual numpy development, it is very necessary to understand the characteristics and performance of the numpy version and master the numpy version viewing skills, which can lay a solid foundation for better numpy application and development.

The above is the detailed content of Tips and tricks for viewing numpy versions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

A concise tutorial on Java source code viewing techniques: a quick way to master it A concise tutorial on Java source code viewing techniques: a quick way to master it Dec 28, 2023 am 08:26 AM

Simple Tutorial: Quickly Learn Java Source Code Viewing Techniques Java is a widely used programming language, and many developers will read and study Java source code. However, for beginners, reading complex source code can be confusing and overwhelming. This article will introduce some techniques for quickly learning Java source code to help readers better understand and analyze the source code. 1. Choose a suitable source code reading tool. Before starting to read Java source code, we first need to choose a suitable source code reading tool. Commonly used source code reading tools include

Tips and tricks for viewing numpy versions Tips and tricks for viewing numpy versions Jan 19, 2024 am 10:53 AM

Numpy is a very commonly used mathematics library in Python. It is widely used in the field of scientific computing and supports a large number of numerical calculations, linear algebra, random number generation, Fourier transform and other functions. When using numpy for mathematical calculations, it is often necessary to determine the numpy version and its characteristics, and make different optimization and algorithm selections for different versions of numpy. This article will introduce tips and tricks for checking numpy version, and how to better use numpy by detecting numpy version information. one,

Numpy version iteration guide Numpy version iteration guide Feb 18, 2024 pm 09:54 PM

From old version to new version: Numpy version update guide 1. Introduction Numpy is one of the most commonly used mathematics libraries in Python and is widely used in the fields of scientific computing, data analysis and machine learning. Numpy makes processing large-scale data sets more efficient and easier by providing efficient array operations and mathematical functions. Although Numpy had many powerful features when it was initially released, over time, Numpy continued to receive version updates and feature improvements based on feedback from developers and users. every new version

Introducing the latest version of numpy: introducing the latest features and improvements Introducing the latest version of numpy: introducing the latest features and improvements Feb 19, 2024 pm 01:52 PM

Numpy is an open source numerical computing library based on Python. It is widely used and favored by many researchers and developers in the fields of scientific computing, data analysis and machine learning. The numpy library provides tools for efficient numerical calculations and data processing through multi-dimensional array objects and a set of functions for manipulating these arrays. In recent years, the numpy library has been continuously updated, and each version brings new features and improvements, allowing users to use it more efficiently to carry out various data computing tasks. This article will introduce numpy

What is Alipay's basement used for_basement opening tips What is Alipay's basement used for_basement opening tips Jan 07, 2024 pm 12:10 PM

Alipay recently launched an interesting new feature called Basement. Since this is a new feature, many users don’t know what Alipay’s basement is used for or how to enter it. I will introduce it to you below, hoping it can help you. What is the purpose of Alipay's basement? Alipay’s basement function refers to a small program entrance added at the bottom of the Alipay application. Users can take a break or draw lots by entering the basement function of Alipay. At the same time, some merchants' coupons or advertisements will also appear here. Users can click on these icons to enter the merchant's mini program to achieve one-stop shopping. In addition, Alipay’s basement function also provides a music playback function, where users can enjoy music. After introducing the Alipay basement function,

Quickly master the skills of PyCharm project packaging Quickly master the skills of PyCharm project packaging Dec 30, 2023 pm 12:37 PM

Master the tricks of PyCharm project packaging in one minute. PyCharm is a powerful Python integrated development environment (IDE) that provides many useful functions to help developers write and debug Python code more efficiently. One of the important functions is project packaging, which can package the entire project into an executable file or a distributable package. This article will introduce tips on how to use PyCharm for project packaging. In order to better help readers understand, we will provide specific code examples. In the beginning

Data table viewing skills in MySQL Data table viewing skills in MySQL Jun 15, 2023 pm 05:56 PM

As a relational database management system widely used in Web applications, MySQL is a commonly used database platform. When using MySQL, operating data tables is a basic skill. This article will introduce some data table viewing skills in MySQL so that administrators and developers can better understand and utilize this powerful database management system. 1. Use the command line to view the data table 1.1 Query the data table In MySQL, you can use the SELECT statement to query the data table. For example, such as

php CodeIgniter advanced tips: make your website stand out php CodeIgniter advanced tips: make your website stand out Feb 19, 2024 pm 11:03 PM

CodeIgniter is a powerful PHP framework that helps you develop WEB applications quickly and easily. It provides many built-in functions and features that can help you improve development efficiency and application performance. However, CodeIgniter also has some lesser-known tips and tricks that can help you create more powerful and flexible web applications. 1. Use hooks to extend CodeIgniter’s functionality Hooks are an event system in CodeIgniter that allow you to execute custom code when specific events occur. This can be used to extend CodeIgniter's functionality, or to add custom logic to your application. For example, you can use hooks to: on every load

See all articles