Related Articles

# How to create an empty and a full NumPy array?

• Last Updated : 01 Oct, 2020

Sometimes there is a need to create an empty and full array simultaneously for a particular question. In this situation, we have two functions named as numpy.empty() and numpy.full() to create an empty and full arrays.

Syntax:

```numpy.full(shape, fill_value, dtype = None, order = ‘C’)
numpy.empty(shape, dtype = float, order = ‘C’)
```

Example 1:

## Python3

 `# python program to create``# Empty and Full Numpy arrays`` ` `import` `numpy as np`` ` ` ` `# Create an empty array``empa ``=` `np.empty((``3``, ``4``), dtype``=``int``)``print``(``"Empty Array"``)``print``(empa)`` ` `# Create a full array``flla ``=` `np.full([``3``, ``3``], ``55``, dtype``=``int``)``print``(``"\n Full Array"``)``print``(flla)`

Output: In the above example, we create an empty array of 3X4 and full array of 3X3 of INTEGER type.

Example 2:

## Python3

 `# python program to create``# Empty and Full Numpy arrays`` ` `import` `numpy as np`` ` ` ` `# Create an empty array``empa ``=` `np.empty([``4``, ``2``])``print``(``"Empty Array"``)``print``(empa)`` ` `# Create a full array``flla ``=` `np.full([``4``, ``3``], ``95``)``print``(``"\n Full Array"``)``print``(flla)`

Output: In the above example, we create an empty array of 4X2 and full array of 4X3 of INTEGER and FLOAT type.

Example 3:

## Python3

 `# python program to create ``# Empty and Full Numpy arrays`` ` `import` `numpy as np`` ` `# Create an empty array``empa ``=`  `np.empty([``3``,``3``]) ``print``(``"Empty Array"``)``print``(empa)`` ` `# Create a full array``flla ``=` `np.full([``5``,``3``], ``9.9``)``print``(``"\n Full Array"``)``print``(flla)`

Output: In the above example, we create an empty array of 3X3 and full array of 5X3 of FLOAT type.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.5962514,"math_prob":0.8913233,"size":1858,"snap":"2021-31-2021-39","text_gpt3_token_len":529,"char_repetition_ratio":0.17367853,"word_repetition_ratio":0.42897728,"special_character_ratio":0.2911733,"punctuation_ratio":0.13461539,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95119673,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,4,null,4,null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-25T07:44:18Z\",\"WARC-Record-ID\":\"<urn:uuid:6feeafdf-b637-43d5-aaef-0e0789bc585a>\",\"Content-Length\":\"112879\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5df45979-aa67-4ad6-aa62-d0043eaa127c>\",\"WARC-Concurrent-To\":\"<urn:uuid:9f3129ba-0fce-42e2-b7c8-6ac072076ff6>\",\"WARC-IP-Address\":\"23.45.233.19\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/how-to-create-an-empty-and-a-full-numpy-array/\",\"WARC-Payload-Digest\":\"sha1:VBCLMQUEDLBAOLRRMKDLD4VUKDVKB6HZ\",\"WARC-Block-Digest\":\"sha1:JLYA3Q6ZJJ3LEX5J3R3IWNL2KUMOVDLD\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057598.98_warc_CC-MAIN-20210925052020-20210925082020-00695.warc.gz\"}"}