Change language

Numpy MaskedArray.atleast_1d () Function | python

| |

numpy.MaskedArray.atleast_1d() is used to transform input data into masked arrays with at least one dimension. numpy.MaskedArray.atleast_1d() the input is converted to one-dimensional arrays, while the larger input is preserved.

Syntax: numpy.ma.atleast_1d(*arys)

Parameters:
arys: [array_like] One or more input arrays.

Return: [ndarray] An array, or list of arrays, each with arr.ndim" = 1

Code # 1:

# Python program explaining
# numpy.MaskedArray.atleast_1d () method

 
# import numy as geek
# and numpy.ma module as ma

import numpy as geek 

import numpy.ma as ma 

 
# create input arrays

in_arr1 = geek.array ([[ 1 , 2 ], [ 3 , - 1 ], [ 5 , - 3 ]])

print ( " 1st Input array: " , in_arr1)

 

in_arr2 = geek.array ( 2 )

print ( "2nd Input array:" , in_arr2)

 
# We are now creating a masked array.
# invalidating the post.

mask_arr1 = ma.masked_array (in_arr1, mask = [[ 1 , 0 ], [ 0 , 1 ], [ 0 , 0 ]]) 

print ( " 1st Masked array: " , mask_arr1)

  

mask_arr2 = ma.masked_array (in_arr2, mask = 0

print ( "2nd Masked array:" , mask_arr2)

 
# applying MaskedArray.atleast_1d methods
# to the masked array

out_arr = ma.atleast_1d (mask_arr1, mask_arr2) 

print ( "Output masked array:" , out_arr) 

Output :

 1st Input array: [[1 2] [3 -1] [5 -3]] 2nd Input array: 2 1st Masked array: [[- 2] [3 -] [5 -3]] 2nd Masked array: 2 Output masked array: [masked_array (data = [[-, 2], [3, -], [ 5, -3]], mask = [[True, False], [False, True], [False, False]], fill_value = 999999), masked_array (data = [2], mask = [False], fill_value = 999999)] 

Code # 2:

# Python program explaining
# numpy.MaskedArray.atleast_1d () method

 
# import numy as geek
# and numpy.ma module as ma

import numpy as g eek 

import numpy.ma as ma 

 
# create input array

in_arr = geek.array ([[[ 2e8 , 3e - 5 ]], [[ - 45.0 , 2e5 ]]])

print ( "Input array:" , in_arr)

 
# Now we create a masked array.
# making one entry invalid .

mask_arr = ma.masked_array ( in_arr, mask = [[[[ 1 , 0 ]], [[ 0 , 0 ]]]) 

print ( "3D Masked array:" , mask_arr) 

 
# applying methods MaskedArray.atleast_1d
# into the masked array

out_arr = ma.atleast_1d (mask_arr) 

print ( " Ou tput masked array: " , out_arr)

Output:

 Input array: [[[2.0e + 08 3.0e-05]] [[-4.5e + 01 2.0e + 05]]] 3D Masked array : [[[- 3e-05]] [[-45.0 200000.0]]] Output masked array: [[[- 3e-05]] [[-45.0 200000.0]]] 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically