Skip to content

Python

Python is a high-level, interpreted, general-purpose programming language emphasizing code readability, simplicity, and developer productivity.


Its elegant syntax, dynamic typing, and extensive standard library, combined with a vast ecosystem of mature third-party packages, make it the leading choice for web development, data science, machine learning, automation, scientific computing, DevOps, and rapid application prototyping across industries.


How to Customize Standard Python Environment?

Section titled “How to Customize Standard Python Environment?”

Currently the standard Python environment allow users to install extra packages by running pip install <package> command.


To create custom environment, run below command in the SSH terminal (CLI), for tutorial in accessing CLI, please refer to SSH Shell Access to EdUHK HPC Platform and Cluster (Web-based Shell Access)


# Load python module (use Python 3.10 environment as example)
$ module load python/3.10
# Install extra packages
$ python -m pip install <packages>
# List all installed packages
$ pip list
# Purge module
$ module purge

All new installed extra package will be located in /home/$USER/.local/


How to Reset Customized Python Environment as Default?

Section titled “How to Reset Customized Python Environment as Default?”

To reset the customized standard python environment as default, run below command in the SSH terminal (CLI), for tutorial in accessing CLI, please refer to SSH Shell Access to EdUHK HPC Platform and Cluster (Web-based Shell Access)


# Load python module
$ module load python/<version>
# Reset user’s python environment
$ pip freeze | xargs pip uninstall -y
# Purge module
$ module purge

How to Create Customized Python Environment by Anaconda?

Section titled “How to Create Customized Python Environment by Anaconda?”

To create custom Python environment by Anaconda, please refer to How to Create Customized Environment by Anaconda?


How to Remove Customized Python Environment (Anaconda)?

Section titled “How to Remove Customized Python Environment (Anaconda)?”

To create custom Python environment by Anaconda, please refer to How to Remove Customized Environment (Anaconda)?


Example source code path → /home/$USER/job_template/python/numpy_test.py

import numpy as np
# Create a 1-dimensional array (vector)
array_1d = np.array([1, 2, 3, 4, 5])
print("1D Array:", array_1d)
# Create a 2-dimensional array (matrix)
array_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("\n2D Array:\n", array_2d)
# Perform element-wise operations
sum_array = array_1d + 10
print("\n1D Array after adding 10 to each element:", sum_array)
product_array = array_2d * 2
print("\n2D Array after multiplying each element by 2:\n", product_array)
# Access elements using indexing and slicing
print("\nElement at index 2 of 1D array:", array_1d[2])
print("First row of 2D array:", array_2d[0])
print("Elements from index 1 to 3 of 1D array:", array_1d[1:4])
# Get array attributes
print("\nShape of 2D array:", array_2d.shape)
print("Number of dimensions of 2D array:", array_2d.ndim)
print("Data type of elements in 1D array:", array_1d.dtype)

For more information about Python, please refer to: Python Document Site