numpy.MaskedArray.astype()
restituisce una copia del cast di MaskedArray a questo nuovo tipo.
Sintassi:
numpy.MaskedArray.astype(newtype)
Parametri:
newtype: digita in cui vogliamo convertire l’array mascherato.Ritorno: [MaskedArray] Una copia del cast automatico per inserire newtype. La forma del record restituito corrisponde a self.shape.
Codice n. 1:
|
Output:
Input array: [1 2 3 -1 5] Masked array: [1 2 - -1 5] int32 Output typecasted array: [1.0 2.0 - -1.0 5.0] float64
Codice n. 2:
# Spiegazione del programma Python
# metodo numpy.MaskedArray.astype ()
# import numy as geek
# e modulo numpy.ma as ma
import
numpy as geek
import
numpy.ma as ma
,
50.5
], dtype
=
’float64’
)
print
(
" Array di input: "
, in_arr)
# Ora creiamo un array mascherato, creando
# la prima e la terza voce non sono valide.
mask_arr
=
ma.masked_array ( in_arr, mask
0
,
1
,
0
,
0
, mask_arr)
# print dati come un aaray mascherato
print
(mask_arr.dtype)
# utilizzo dei metodi MaskedArray.astype per mascherare l’array
# e convertilo in int32
out_arr
=
mask_arr.astype (
’int32’
)
print
(
"Output typecasted array: "
, out_arr)
# print data type Typecasted Masque Aaray
print
(out_arr.dtype)
Output :
Array di input: [10.1 20.2 30.3 40.4 50.5] Array mascherato: [- 20.2 - 40.4 50.5 ] float64 Output typecasted array: [- 20 - 40 50] int32
Ci auguriamo che questo articolo ti abbia aiutato a risolvere il problema. Oltre a Numpy MaskedArray.astype () Funzione | Python, controlla altri argomenti relativi a Python functions.
Vuoi eccellere in Python? Consulta la nostra recensione dei migliori corsi online Python 2023. Se sei interessato alla scienza dei dati, controlla anche come imparare a programmare in R.
A proposito, questo materiale è disponibile anche in altre lingue:
- Numpy MaskedArray.astype () Funzione | Python
- Italiano Numpy MaskedArray.astype () Funzione | Python
- Deutsch Numpy MaskedArray.astype () Funzione | Python
- Français Numpy MaskedArray.astype () Funzione | Python
- Español Numpy MaskedArray.astype () Funzione | Python
- Türk Numpy MaskedArray.astype () Funzione | Python
- Русский Numpy MaskedArray.astype () Funzione | Python
- Português Numpy MaskedArray.astype () Funzione | Python
- Polski Numpy MaskedArray.astype () Funzione | Python
- Nederlandse Numpy MaskedArray.astype () Funzione | Python
- 中文 Numpy MaskedArray.astype () Funzione | Python
- 한국어 Numpy MaskedArray.astype () Funzione | Python
- 日本語 Numpy MaskedArray.astype () Funzione | Python
- हिन्दी Numpy MaskedArray.astype () Funzione | Python
Abu Dhabi | 2023-01-31
Mi stavo preparando per il mio colloquio di codifica, grazie per aver chiarito questo punto - Numpy MaskedArray.astype () Funzione | Python in Python non è il più semplice. Lo userò nella mia tesi di laurea
Vigrinia | 2023-01-31
Python functions è tutto un po' confuso 😭 Numpy MaskedArray.astype () Funzione | Python non è l'unico problema che ho riscontrato. Lo userò nella mia tesi di laurea
Berlin | 2023-01-31
Semplice e chiaro. Grazie per la condivisione. Il mio punto debole è sempre stato il Numpy MaskedArray.astype () Funzione | Python e altri problemi con il Python functions 😁. Controllato ieri, funziona!
Shop
Latest questions