Change language

Numpy recarray.dot () function | python

| |

numpy.recarray.dot() returns the product of two arrays of records.

Syntax: numpy.recarray.dot (arr, out = None)

Parameters:
arr: array of the second record ... 
out: [ndarray, optional] Location where the result is stored. 
-" If provided, it should have the form to which the inputs are translated. 
-" If not specified or No, the newly allocated array is returned.

Return: Returns a new array containing the result, unless out is specified, in which case it is returned.

Code # 1:

# Python program explaining
# numpy.recarray.dot () method

 
# import numy as geek

import numpy as geek

 
# create 2 input arrays with 2 different fields

in_arr1 = geek.array ([[( 5.0 , 2 ), ( 3.0 , - 4 ), ( 6.0 , 9 )],

[( 9.0 , 1 ), ( 5.0 , 4 ), ( - 12.0 , - 7 ) ]],

dtype = [( ’a’ , float ), ( ’ b’ , int )])

 

in_arr2 = geek.array ([[( 2.0 , 1 ), ( 4.0 , - 3 )],

  [( 8.0 , 3 ), ( 6.0 , 5 )],

[( 6.0 , - 5 ), ( - 5.0 , 4 )]],

dtype = [( ’a ’ , float ), ( ’b’ , int )])

 

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

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

 
# convert it to array of posts,
# using arr.view (np.recarray)

rec_arr1 = in_arr1.view (geek.recarray)

print ( "1st Record array of float:" , rec_arr1. a)

print ( "1st Record array of int: " , rec_arr1.b)

rec_arr2 = in_arr2.view (geek.recarray)

print ( "2nd Record array of float:" , rec_arr2.a)

print ( "2nd Record array of int:" , rec_arr2.b)

  
# applying recarray.dot methods
# between two arrays of floating point records

out_arr1 = rec_arr1.a.dot (rec_arr2.a)

print ( "Output float array :" , out_arr1) 

 
# using recarray.dot methods
# between two arrays of int records

out_arr1 = rec_arr1.b.dot (rec_arr2.b)

prin t ( "Output int array :" , out_arr1) 

Exit:

 1st Input array: [[ (5., 2) (3., -4) (6., 9)] [(9., 1) (5., 4) (-12., -7)]] 2nd Input array: [[( 2., 1) (4., -3)] [(8., 3) (6., 5)] [(6., -5) (-5., 4)]] 1st Record array of float: [[5. 3. 6.] [9. 5. -12.]] 1st Record array of int: [[2 -4 9] [1 4 -7]] 2nd Record array of float: [[2. 4 .] [8. 6.] [6. -5.]] 2nd Record array of int: [[1 -3] [3 5] [-5 4]] Output float array: [[70. 8.] [ -fourteen. 126.]] Output int array: [[-55 10] [48 -11]] 

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