or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-creation.mdarray-statistics.mddata-types.mdfft.mdindex.mdinput-output.mdlinear-algebra.mdmasked-arrays.mdmathematical-functions.mdpolynomial.mdrandom-generation.mdsearching-sorting.md

mathematical-functions.mddocs/

0

# Mathematical Functions

1

2

Universal functions (ufuncs) providing element-wise mathematical operations with automatic broadcasting. These functions operate on arrays element-by-element and support output to pre-allocated arrays for memory efficiency.

3

4

## Capabilities

5

6

### Arithmetic Operations

7

8

Basic arithmetic operations between arrays and scalars.

9

10

```python { .api }

11

def add(x1, x2, out=None, **kwargs):

12

"""

13

Add arguments element-wise.

14

15

Parameters:

16

- x1, x2: array_like, input arrays to add

17

- out: ndarray, array to store results

18

- **kwargs: ufunc keyword arguments

19

20

Returns:

21

ndarray: Element-wise sum of x1 and x2

22

"""

23

24

def subtract(x1, x2, out=None, **kwargs):

25

"""

26

Subtract arguments element-wise.

27

28

Parameters:

29

- x1, x2: array_like, input arrays

30

- out: ndarray, array to store results

31

- **kwargs: ufunc keyword arguments

32

33

Returns:

34

ndarray: Element-wise difference x1 - x2

35

"""

36

37

def multiply(x1, x2, out=None, **kwargs):

38

"""

39

Multiply arguments element-wise.

40

41

Parameters:

42

- x1, x2: array_like, input arrays

43

- out: ndarray, array to store results

44

- **kwargs: ufunc keyword arguments

45

46

Returns:

47

ndarray: Element-wise product of x1 and x2

48

"""

49

50

def divide(x1, x2, out=None, **kwargs):

51

"""

52

Returns element-wise true division of inputs.

53

54

Parameters:

55

- x1, x2: array_like, input arrays

56

- out: ndarray, array to store results

57

- **kwargs: ufunc keyword arguments

58

59

Returns:

60

ndarray: Element-wise division x1 / x2

61

"""

62

63

def true_divide(x1, x2, out=None, **kwargs):

64

"""

65

Returns element-wise true division of inputs.

66

67

Parameters:

68

- x1, x2: array_like, input arrays

69

- out: ndarray, array to store results

70

- **kwargs: ufunc keyword arguments

71

72

Returns:

73

ndarray: Element-wise true division x1 / x2

74

"""

75

76

def floor_divide(x1, x2, out=None, **kwargs):

77

"""

78

Returns element-wise floor division of inputs.

79

80

Parameters:

81

- x1, x2: array_like, input arrays

82

- out: ndarray, array to store results

83

- **kwargs: ufunc keyword arguments

84

85

Returns:

86

ndarray: Element-wise floor division x1 // x2

87

"""

88

89

def power(x1, x2, out=None, **kwargs):

90

"""

91

First array elements raised to powers from second array, element-wise.

92

93

Parameters:

94

- x1, x2: array_like, input arrays

95

- out: ndarray, array to store results

96

- **kwargs: ufunc keyword arguments

97

98

Returns:

99

ndarray: Element-wise power x1 ** x2

100

"""

101

102

def mod(x1, x2, out=None, **kwargs):

103

"""

104

Returns element-wise remainder of division.

105

106

Parameters:

107

- x1, x2: array_like, input arrays

108

- out: ndarray, array to store results

109

- **kwargs: ufunc keyword arguments

110

111

Returns:

112

ndarray: Element-wise remainder x1 % x2

113

"""

114

115

def remainder(x1, x2, out=None, **kwargs):

116

"""

117

Returns element-wise remainder of division.

118

119

Parameters:

120

- x1, x2: array_like, input arrays

121

- out: ndarray, array to store results

122

- **kwargs: ufunc keyword arguments

123

124

Returns:

125

ndarray: Element-wise remainder

126

"""

127

128

def divmod(x1, x2, out1=None, out2=None, **kwargs):

129

"""

130

Returns element-wise quotient and remainder simultaneously.

131

132

Parameters:

133

- x1, x2: array_like, input arrays

134

- out1, out2: ndarray, arrays to store quotient and remainder

135

- **kwargs: ufunc keyword arguments

136

137

Returns:

138

tuple of ndarrays: (quotient, remainder)

139

"""

140

```

141

142

### Unary Arithmetic Functions

143

144

Arithmetic operations on single arrays.

145

146

```python { .api }

147

def negative(x, out=None, **kwargs):

148

"""

149

Numerical negative, element-wise.

150

151

Parameters:

152

- x: array_like, input array

153

- out: ndarray, array to store results

154

- **kwargs: ufunc keyword arguments

155

156

Returns:

157

ndarray: Element-wise negation -x

158

"""

159

160

def positive(x, out=None, **kwargs):

161

"""

162

Numerical positive, element-wise.

163

164

Parameters:

165

- x: array_like, input array

166

- out: ndarray, array to store results

167

- **kwargs: ufunc keyword arguments

168

169

Returns:

170

ndarray: Element-wise positive +x

171

"""

172

173

def absolute(x, out=None, **kwargs):

174

"""

175

Calculate absolute value element-wise.

176

177

Parameters:

178

- x: array_like, input array

179

- out: ndarray, array to store results

180

- **kwargs: ufunc keyword arguments

181

182

Returns:

183

ndarray: Element-wise absolute values

184

"""

185

186

def abs(x, out=None, **kwargs):

187

"""

188

Calculate absolute value element-wise (alias for absolute).

189

190

Parameters:

191

- x: array_like, input array

192

- out: ndarray, array to store results

193

- **kwargs: ufunc keyword arguments

194

195

Returns:

196

ndarray: Element-wise absolute values

197

"""

198

199

def sign(x, out=None, **kwargs):

200

"""

201

Returns element-wise sign of number.

202

203

Parameters:

204

- x: array_like, input array

205

- out: ndarray, array to store results

206

- **kwargs: ufunc keyword arguments

207

208

Returns:

209

ndarray: Element-wise sign (-1, 0, or 1)

210

"""

211

212

def reciprocal(x, out=None, **kwargs):

213

"""

214

Return reciprocal of argument, element-wise.

215

216

Parameters:

217

- x: array_like, input array

218

- out: ndarray, array to store results

219

- **kwargs: ufunc keyword arguments

220

221

Returns:

222

ndarray: Element-wise reciprocal 1/x

223

"""

224

```

225

226

### Trigonometric Functions

227

228

Trigonometric operations in radians.

229

230

```python { .api }

231

def sin(x, out=None, **kwargs):

232

"""

233

Trigonometric sine, element-wise.

234

235

Parameters:

236

- x: array_like, input array in radians

237

- out: ndarray, array to store results

238

- **kwargs: ufunc keyword arguments

239

240

Returns:

241

ndarray: Element-wise sine values

242

"""

243

244

def cos(x, out=None, **kwargs):

245

"""

246

Cosine, element-wise.

247

248

Parameters:

249

- x: array_like, input array in radians

250

- out: ndarray, array to store results

251

- **kwargs: ufunc keyword arguments

252

253

Returns:

254

ndarray: Element-wise cosine values

255

"""

256

257

def tan(x, out=None, **kwargs):

258

"""

259

Compute tangent element-wise.

260

261

Parameters:

262

- x: array_like, input array in radians

263

- out: ndarray, array to store results

264

- **kwargs: ufunc keyword arguments

265

266

Returns:

267

ndarray: Element-wise tangent values

268

"""

269

270

def arcsin(x, out=None, **kwargs):

271

"""

272

Inverse sine, element-wise.

273

274

Parameters:

275

- x: array_like, input array in [-1, 1]

276

- out: ndarray, array to store results

277

- **kwargs: ufunc keyword arguments

278

279

Returns:

280

ndarray: Element-wise arcsine in radians

281

"""

282

283

def arccos(x, out=None, **kwargs):

284

"""

285

Trigonometric inverse cosine, element-wise.

286

287

Parameters:

288

- x: array_like, input array in [-1, 1]

289

- out: ndarray, array to store results

290

- **kwargs: ufunc keyword arguments

291

292

Returns:

293

ndarray: Element-wise arccosine in radians

294

"""

295

296

def arctan(x, out=None, **kwargs):

297

"""

298

Trigonometric inverse tangent, element-wise.

299

300

Parameters:

301

- x: array_like, input array

302

- out: ndarray, array to store results

303

- **kwargs: ufunc keyword arguments

304

305

Returns:

306

ndarray: Element-wise arctangent in radians

307

"""

308

309

def arctan2(x1, x2, out=None, **kwargs):

310

"""

311

Element-wise arc tangent of x1/x2 choosing quadrant correctly.

312

313

Parameters:

314

- x1, x2: array_like, y and x coordinates

315

- out: ndarray, array to store results

316

- **kwargs: ufunc keyword arguments

317

318

Returns:

319

ndarray: Element-wise arctangent of x1/x2 in radians

320

"""

321

```

322

323

### Hyperbolic Functions

324

325

Hyperbolic trigonometric functions.

326

327

```python { .api }

328

def sinh(x, out=None, **kwargs):

329

"""

330

Hyperbolic sine, element-wise.

331

332

Parameters:

333

- x: array_like, input array

334

- out: ndarray, array to store results

335

- **kwargs: ufunc keyword arguments

336

337

Returns:

338

ndarray: Element-wise hyperbolic sine

339

"""

340

341

def cosh(x, out=None, **kwargs):

342

"""

343

Hyperbolic cosine, element-wise.

344

345

Parameters:

346

- x: array_like, input array

347

- out: ndarray, array to store results

348

- **kwargs: ufunc keyword arguments

349

350

Returns:

351

ndarray: Element-wise hyperbolic cosine

352

"""

353

354

def tanh(x, out=None, **kwargs):

355

"""

356

Compute hyperbolic tangent element-wise.

357

358

Parameters:

359

- x: array_like, input array

360

- out: ndarray, array to store results

361

- **kwargs: ufunc keyword arguments

362

363

Returns:

364

ndarray: Element-wise hyperbolic tangent

365

"""

366

367

def arcsinh(x, out=None, **kwargs):

368

"""

369

Inverse hyperbolic sine element-wise.

370

371

Parameters:

372

- x: array_like, input array

373

- out: ndarray, array to store results

374

- **kwargs: ufunc keyword arguments

375

376

Returns:

377

ndarray: Element-wise inverse hyperbolic sine

378

"""

379

380

def arccosh(x, out=None, **kwargs):

381

"""

382

Inverse hyperbolic cosine, element-wise.

383

384

Parameters:

385

- x: array_like, input array with x >= 1

386

- out: ndarray, array to store results

387

- **kwargs: ufunc keyword arguments

388

389

Returns:

390

ndarray: Element-wise inverse hyperbolic cosine

391

"""

392

393

def arctanh(x, out=None, **kwargs):

394

"""

395

Inverse hyperbolic tangent element-wise.

396

397

Parameters:

398

- x: array_like, input array in (-1, 1)

399

- out: ndarray, array to store results

400

- **kwargs: ufunc keyword arguments

401

402

Returns:

403

ndarray: Element-wise inverse hyperbolic tangent

404

"""

405

```

406

407

### Exponential and Logarithmic Functions

408

409

Exponential and logarithmic operations.

410

411

```python { .api }

412

def exp(x, out=None, **kwargs):

413

"""

414

Calculate exponential of all elements in input array.

415

416

Parameters:

417

- x: array_like, input array

418

- out: ndarray, array to store results

419

- **kwargs: ufunc keyword arguments

420

421

Returns:

422

ndarray: Element-wise exponential e^x

423

"""

424

425

def exp2(x, out=None, **kwargs):

426

"""

427

Calculate 2**p for all p in input array.

428

429

Parameters:

430

- x: array_like, input array

431

- out: ndarray, array to store results

432

- **kwargs: ufunc keyword arguments

433

434

Returns:

435

ndarray: Element-wise 2^x

436

"""

437

438

def expm1(x, out=None, **kwargs):

439

"""

440

Calculate exp(x) - 1 for all elements in array.

441

442

Parameters:

443

- x: array_like, input array

444

- out: ndarray, array to store results

445

- **kwargs: ufunc keyword arguments

446

447

Returns:

448

ndarray: Element-wise exp(x) - 1

449

"""

450

451

def log(x, out=None, **kwargs):

452

"""

453

Natural logarithm, element-wise.

454

455

Parameters:

456

- x: array_like, input array

457

- out: ndarray, array to store results

458

- **kwargs: ufunc keyword arguments

459

460

Returns:

461

ndarray: Element-wise natural logarithm

462

"""

463

464

def log2(x, out=None, **kwargs):

465

"""

466

Base-2 logarithm of x.

467

468

Parameters:

469

- x: array_like, input array

470

- out: ndarray, array to store results

471

- **kwargs: ufunc keyword arguments

472

473

Returns:

474

ndarray: Element-wise base-2 logarithm

475

"""

476

477

def log10(x, out=None, **kwargs):

478

"""

479

Return base 10 logarithm of input array, element-wise.

480

481

Parameters:

482

- x: array_like, input array

483

- out: ndarray, array to store results

484

- **kwargs: ufunc keyword arguments

485

486

Returns:

487

ndarray: Element-wise base-10 logarithm

488

"""

489

490

def log1p(x, out=None, **kwargs):

491

"""

492

Return natural logarithm of one plus input array, element-wise.

493

494

Parameters:

495

- x: array_like, input array

496

- out: ndarray, array to store results

497

- **kwargs: ufunc keyword arguments

498

499

Returns:

500

ndarray: Element-wise log(1 + x)

501

"""

502

503

def logaddexp(x1, x2, out=None, **kwargs):

504

"""

505

Logarithm of sum of exponentials of inputs.

506

507

Parameters:

508

- x1, x2: array_like, input arrays

509

- out: ndarray, array to store results

510

- **kwargs: ufunc keyword arguments

511

512

Returns:

513

ndarray: Element-wise log(exp(x1) + exp(x2))

514

"""

515

516

def logaddexp2(x1, x2, out=None, **kwargs):

517

"""

518

Logarithm of sum of exponentials of inputs in base-2.

519

520

Parameters:

521

- x1, x2: array_like, input arrays

522

- out: ndarray, array to store results

523

- **kwargs: ufunc keyword arguments

524

525

Returns:

526

ndarray: Element-wise log2(2^x1 + 2^x2)

527

"""

528

```

529

530

### Power and Root Functions

531

532

Power and square root operations.

533

534

```python { .api }

535

def sqrt(x, out=None, **kwargs):

536

"""

537

Return non-negative square-root of array, element-wise.

538

539

Parameters:

540

- x: array_like, input array

541

- out: ndarray, array to store results

542

- **kwargs: ufunc keyword arguments

543

544

Returns:

545

ndarray: Element-wise square root

546

"""

547

548

def square(x, out=None, **kwargs):

549

"""

550

Return element-wise square of input.

551

552

Parameters:

553

- x: array_like, input array

554

- out: ndarray, array to store results

555

- **kwargs: ufunc keyword arguments

556

557

Returns:

558

ndarray: Element-wise square x^2

559

"""

560

561

def cbrt(x, out=None, **kwargs):

562

"""

563

Return cube-root of array, element-wise.

564

565

Parameters:

566

- x: array_like, input array

567

- out: ndarray, array to store results

568

- **kwargs: ufunc keyword arguments

569

570

Returns:

571

ndarray: Element-wise cube root

572

"""

573

```

574

575

### Comparison Functions

576

577

Element-wise comparison operations.

578

579

```python { .api }

580

def equal(x1, x2, out=None, **kwargs):

581

"""

582

Return (x1 == x2) element-wise.

583

584

Parameters:

585

- x1, x2: array_like, input arrays to compare

586

- out: ndarray, array to store results

587

- **kwargs: ufunc keyword arguments

588

589

Returns:

590

ndarray: Boolean array of equality comparison

591

"""

592

593

def not_equal(x1, x2, out=None, **kwargs):

594

"""

595

Return (x1 != x2) element-wise.

596

597

Parameters:

598

- x1, x2: array_like, input arrays to compare

599

- out: ndarray, array to store results

600

- **kwargs: ufunc keyword arguments

601

602

Returns:

603

ndarray: Boolean array of inequality comparison

604

"""

605

606

def less(x1, x2, out=None, **kwargs):

607

"""

608

Return truth value of (x1 < x2) element-wise.

609

610

Parameters:

611

- x1, x2: array_like, input arrays to compare

612

- out: ndarray, array to store results

613

- **kwargs: ufunc keyword arguments

614

615

Returns:

616

ndarray: Boolean array of less-than comparison

617

"""

618

619

def less_equal(x1, x2, out=None, **kwargs):

620

"""

621

Return truth value of (x1 <= x2) element-wise.

622

623

Parameters:

624

- x1, x2: array_like, input arrays to compare

625

- out: ndarray, array to store results

626

- **kwargs: ufunc keyword arguments

627

628

Returns:

629

ndarray: Boolean array of less-than-or-equal comparison

630

"""

631

632

def greater(x1, x2, out=None, **kwargs):

633

"""

634

Return truth value of (x1 > x2) element-wise.

635

636

Parameters:

637

- x1, x2: array_like, input arrays to compare

638

- out: ndarray, array to store results

639

- **kwargs: ufunc keyword arguments

640

641

Returns:

642

ndarray: Boolean array of greater-than comparison

643

"""

644

645

def greater_equal(x1, x2, out=None, **kwargs):

646

"""

647

Return truth value of (x1 >= x2) element-wise.

648

649

Parameters:

650

- x1, x2: array_like, input arrays to compare

651

- out: ndarray, array to store results

652

- **kwargs: ufunc keyword arguments

653

654

Returns:

655

ndarray: Boolean array of greater-than-or-equal comparison

656

"""

657

658

def maximum(x1, x2, out=None, **kwargs):

659

"""

660

Element-wise maximum of array elements.

661

662

Parameters:

663

- x1, x2: array_like, input arrays

664

- out: ndarray, array to store results

665

- **kwargs: ufunc keyword arguments

666

667

Returns:

668

ndarray: Element-wise maximum values

669

"""

670

671

def minimum(x1, x2, out=None, **kwargs):

672

"""

673

Element-wise minimum of array elements.

674

675

Parameters:

676

- x1, x2: array_like, input arrays

677

- out: ndarray, array to store results

678

- **kwargs: ufunc keyword arguments

679

680

Returns:

681

ndarray: Element-wise minimum values

682

"""

683

684

def fmax(x1, x2, out=None, **kwargs):

685

"""

686

Element-wise maximum, ignoring NaNs.

687

688

Parameters:

689

- x1, x2: array_like, input arrays

690

- out: ndarray, array to store results

691

- **kwargs: ufunc keyword arguments

692

693

Returns:

694

ndarray: Element-wise maximum ignoring NaN

695

"""

696

697

def fmin(x1, x2, out=None, **kwargs):

698

"""

699

Element-wise minimum, ignoring NaNs.

700

701

Parameters:

702

- x1, x2: array_like, input arrays

703

- out: ndarray, array to store results

704

- **kwargs: ufunc keyword arguments

705

706

Returns:

707

ndarray: Element-wise minimum ignoring NaN

708

"""

709

```

710

711

### Logical Functions

712

713

Element-wise logical operations.

714

715

```python { .api }

716

def logical_and(x1, x2, out=None, **kwargs):

717

"""

718

Compute truth value of x1 AND x2 element-wise.

719

720

Parameters:

721

- x1, x2: array_like, input arrays

722

- out: ndarray, array to store results

723

- **kwargs: ufunc keyword arguments

724

725

Returns:

726

ndarray: Boolean array of logical AND

727

"""

728

729

def logical_or(x1, x2, out=None, **kwargs):

730

"""

731

Compute truth value of x1 OR x2 element-wise.

732

733

Parameters:

734

- x1, x2: array_like, input arrays

735

- out: ndarray, array to store results

736

- **kwargs: ufunc keyword arguments

737

738

Returns:

739

ndarray: Boolean array of logical OR

740

"""

741

742

def logical_not(x, out=None, **kwargs):

743

"""

744

Compute truth value of NOT x element-wise.

745

746

Parameters:

747

- x: array_like, input array

748

- out: ndarray, array to store results

749

- **kwargs: ufunc keyword arguments

750

751

Returns:

752

ndarray: Boolean array of logical NOT

753

"""

754

755

def logical_xor(x1, x2, out=None, **kwargs):

756

"""

757

Compute truth value of x1 XOR x2 element-wise.

758

759

Parameters:

760

- x1, x2: array_like, input arrays

761

- out: ndarray, array to store results

762

- **kwargs: ufunc keyword arguments

763

764

Returns:

765

ndarray: Boolean array of logical XOR

766

"""

767

```

768

769

### Bitwise Operations

770

771

Bitwise operations on integer arrays.

772

773

```python { .api }

774

def bitwise_and(x1, x2, out=None, **kwargs):

775

"""

776

Compute bitwise AND of two arrays element-wise.

777

778

Parameters:

779

- x1, x2: array_like, input arrays (integers only)

780

- out: ndarray, array to store results

781

- **kwargs: ufunc keyword arguments

782

783

Returns:

784

ndarray: Element-wise bitwise AND

785

"""

786

787

def bitwise_or(x1, x2, out=None, **kwargs):

788

"""

789

Compute bitwise OR of two arrays element-wise.

790

791

Parameters:

792

- x1, x2: array_like, input arrays (integers only)

793

- out: ndarray, array to store results

794

- **kwargs: ufunc keyword arguments

795

796

Returns:

797

ndarray: Element-wise bitwise OR

798

"""

799

800

def bitwise_xor(x1, x2, out=None, **kwargs):

801

"""

802

Compute bitwise XOR of two arrays element-wise.

803

804

Parameters:

805

- x1, x2: array_like, input arrays (integers only)

806

- out: ndarray, array to store results

807

- **kwargs: ufunc keyword arguments

808

809

Returns:

810

ndarray: Element-wise bitwise XOR

811

"""

812

813

def bitwise_not(x, out=None, **kwargs):

814

"""

815

Compute bit-wise inversion, or bit-wise NOT, element-wise.

816

817

Parameters:

818

- x: array_like, input array (integers only)

819

- out: ndarray, array to store results

820

- **kwargs: ufunc keyword arguments

821

822

Returns:

823

ndarray: Element-wise bitwise NOT

824

"""

825

826

def invert(x, out=None, **kwargs):

827

"""

828

Compute bit-wise inversion, or bit-wise NOT, element-wise.

829

830

Parameters:

831

- x: array_like, input array (integers only)

832

- out: ndarray, array to store results

833

- **kwargs: ufunc keyword arguments

834

835

Returns:

836

ndarray: Element-wise bitwise inversion

837

"""

838

839

def left_shift(x1, x2, out=None, **kwargs):

840

"""

841

Shift bits of integer to the left.

842

843

Parameters:

844

- x1, x2: array_like, input arrays (integers only)

845

- out: ndarray, array to store results

846

- **kwargs: ufunc keyword arguments

847

848

Returns:

849

ndarray: Element-wise left bit shift

850

"""

851

852

def right_shift(x1, x2, out=None, **kwargs):

853

"""

854

Shift bits of integer to the right.

855

856

Parameters:

857

- x1, x2: array_like, input arrays (integers only)

858

- out: ndarray, array to store results

859

- **kwargs: ufunc keyword arguments

860

861

Returns:

862

ndarray: Element-wise right bit shift

863

"""

864

```

865

866

### Floating Point Functions

867

868

Floating point specific operations and tests.

869

870

```python { .api }

871

def isfinite(x, out=None, **kwargs):

872

"""

873

Test element-wise for finiteness (not infinity and not NaN).

874

875

Parameters:

876

- x: array_like, input array

877

- out: ndarray, array to store results

878

- **kwargs: ufunc keyword arguments

879

880

Returns:

881

ndarray: Boolean array indicating finite elements

882

"""

883

884

def isinf(x, out=None, **kwargs):

885

"""

886

Test element-wise for positive or negative infinity.

887

888

Parameters:

889

- x: array_like, input array

890

- out: ndarray, array to store results

891

- **kwargs: ufunc keyword arguments

892

893

Returns:

894

ndarray: Boolean array indicating infinite elements

895

"""

896

897

def isnan(x, out=None, **kwargs):

898

"""

899

Test element-wise for NaN and return result as boolean array.

900

901

Parameters:

902

- x: array_like, input array

903

- out: ndarray, array to store results

904

- **kwargs: ufunc keyword arguments

905

906

Returns:

907

ndarray: Boolean array indicating NaN elements

908

"""

909

910

def signbit(x, out=None, **kwargs):

911

"""

912

Returns element-wise True where signbit is set (less than zero).

913

914

Parameters:

915

- x: array_like, input array

916

- out: ndarray, array to store results

917

- **kwargs: ufunc keyword arguments

918

919

Returns:

920

ndarray: Boolean array indicating negative sign bit

921

"""

922

923

def copysign(x1, x2, out=None, **kwargs):

924

"""

925

Change sign of x1 to that of x2, element-wise.

926

927

Parameters:

928

- x1, x2: array_like, input arrays

929

- out: ndarray, array to store results

930

- **kwargs: ufunc keyword arguments

931

932

Returns:

933

ndarray: Element-wise copy of sign from x2 to x1

934

"""

935

936

def nextafter(x1, x2, out=None, **kwargs):

937

"""

938

Return next floating-point value after x1 towards x2, element-wise.

939

940

Parameters:

941

- x1, x2: array_like, input arrays

942

- out: ndarray, array to store results

943

- **kwargs: ufunc keyword arguments

944

945

Returns:

946

ndarray: Next representable floating-point values

947

"""

948

949

def spacing(x, out=None, **kwargs):

950

"""

951

Return distance between x and adjacent number, element-wise.

952

953

Parameters:

954

- x: array_like, input array

955

- out: ndarray, array to store results

956

- **kwargs: ufunc keyword arguments

957

958

Returns:

959

ndarray: Spacing to next floating-point number

960

"""

961

962

def ldexp(x1, x2, out=None, **kwargs):

963

"""

964

Returns x1 * 2**x2, element-wise.

965

966

Parameters:

967

- x1, x2: array_like, mantissa and exponent arrays

968

- out: ndarray, array to store results

969

- **kwargs: ufunc keyword arguments

970

971

Returns:

972

ndarray: Element-wise x1 * 2**x2

973

"""

974

975

def frexp(x, out1=None, out2=None, **kwargs):

976

"""

977

Decompose elements of x into mantissa and twos exponent.

978

979

Parameters:

980

- x: array_like, input array

981

- out1, out2: ndarray, arrays to store mantissa and exponent

982

- **kwargs: ufunc keyword arguments

983

984

Returns:

985

tuple of ndarrays: (mantissa, exponent)

986

"""

987

988

def floor(x, out=None, **kwargs):

989

"""

990

Return floor of input, element-wise.

991

992

Parameters:

993

- x: array_like, input array

994

- out: ndarray, array to store results

995

- **kwargs: ufunc keyword arguments

996

997

Returns:

998

ndarray: Element-wise floor values

999

"""

1000

1001

def ceil(x, out=None, **kwargs):

1002

"""

1003

Return ceiling of input, element-wise.

1004

1005

Parameters:

1006

- x: array_like, input array

1007

- out: ndarray, array to store results

1008

- **kwargs: ufunc keyword arguments

1009

1010

Returns:

1011

ndarray: Element-wise ceiling values

1012

"""

1013

1014

def trunc(x, out=None, **kwargs):

1015

"""

1016

Return truncated value of input, element-wise.

1017

1018

Parameters:

1019

- x: array_like, input array

1020

- out: ndarray, array to store results

1021

- **kwargs: ufunc keyword arguments

1022

1023

Returns:

1024

ndarray: Element-wise truncated values

1025

"""

1026

1027

def rint(x, out=None, **kwargs):

1028

"""

1029

Round elements to nearest integers.

1030

1031

Parameters:

1032

- x: array_like, input array

1033

- out: ndarray, array to store results

1034

- **kwargs: ufunc keyword arguments

1035

1036

Returns:

1037

ndarray: Element-wise rounded to nearest integers

1038

"""

1039

1040

def modf(x, out1=None, out2=None, **kwargs):

1041

"""

1042

Return fractional and integral parts of array, element-wise.

1043

1044

Parameters:

1045

- x: array_like, input array

1046

- out1, out2: ndarray, arrays to store fractional and integral parts

1047

- **kwargs: ufunc keyword arguments

1048

1049

Returns:

1050

tuple of ndarrays: (fractional_part, integral_part)

1051

"""

1052

```

1053

1054

## Usage Examples

1055

1056

### Basic Arithmetic Operations

1057

1058

```python

1059

import numpy as np

1060

1061

# Element-wise arithmetic

1062

a = np.array([1, 2, 3, 4])

1063

b = np.array([5, 6, 7, 8])

1064

1065

sum_result = np.add(a, b) # [6, 8, 10, 12]

1066

diff_result = np.subtract(b, a) # [4, 4, 4, 4]

1067

prod_result = np.multiply(a, b) # [5, 12, 21, 32]

1068

div_result = np.divide(b, a) # [5.0, 3.0, 2.33, 2.0]

1069

1070

# Broadcasting with scalars

1071

scaled = np.multiply(a, 10) # [10, 20, 30, 40]

1072

```

1073

1074

### Trigonometric Functions

1075

1076

```python

1077

import numpy as np

1078

1079

# Trigonometric operations

1080

angles = np.array([0, np.pi/4, np.pi/2, np.pi])

1081

sin_vals = np.sin(angles) # [0, 0.707, 1, 0]

1082

cos_vals = np.cos(angles) # [1, 0.707, 0, -1]

1083

1084

# Convert degrees to radians first

1085

degrees = np.array([0, 45, 90, 180])

1086

radians = np.radians(degrees) # Convert to radians

1087

sin_degrees = np.sin(radians) # Sine of degree values

1088

```

1089

1090

### Exponential and Logarithmic Functions

1091

1092

```python

1093

import numpy as np

1094

1095

# Exponential functions

1096

x = np.array([1, 2, 3])

1097

exp_vals = np.exp(x) # [2.718, 7.389, 20.086]

1098

exp2_vals = np.exp2(x) # [2, 4, 8]

1099

1100

# Logarithmic functions

1101

y = np.array([1, 10, 100])

1102

log_vals = np.log(y) # [0, 2.303, 4.605]

1103

log10_vals = np.log10(y) # [0, 1, 2]

1104

```